The program seeks to delete all the images in a folder. But the program has displayed these images in an ImageView. The last image displayed in the view is somehow "held open:" by the Image class - presumably. It was read by code like this:
File selectedImageFile = new File( sImageFilePath ); /* we appear to have a file so we will try to load the image with it. */ InputStream imageAsStream; try { //assert selectedImageFile != null; imageAsStream = new FileInputStream(selectedImageFile); } catch (FileNotFoundException e) { printSysOut("Somehow, image file not found"); throw new RuntimeException(e); } imgImageView.setVisible( true ); anImage = new Image( imageAsStream ); imgImageView.setImage( anImage );
So when the program attempts to delete the file using:
`
try {
File fSourceFile = new File(sSourceAbsFilePath);
if (fSourceFile.delete()) {
iManyDeleted++;
} else {
SSController.printSysOut(String.format("FileHelperCleanSource Problem Deleting File: %s", sSourceAbsFilePath) );
}
} catch (Exception e) {
//throw new RuntimeException(e);
return String.format("Error deleting source file: %s", sSourceAbsFilePath);
}`
Delete fails with a FALSE.
So the program tries this to clear the image out of the view and toss it out, but is still unable to delete the file: It is still locked apparently.