Объект File хранит имя или путь файла или каталога на диске.
Но он не предоставляет доступ к данным в файле!
Пример разделения имени файла:
bollean work(File file)
{
String filebegin=file.getParent(); //каталог
String filename=file.getName();//имя файла
String ext=filename.substring(filename.lastIndexOf("."));//расширение
filebasename="\\"+filename.substring(0,filename.lastIndexOf(".")-1);
System.out.println(file.toString());//вывести полное имя файла
//Если файл существует
if(new File(filebegin+filebasename+1+fileext).canRead()) return true;
else return false;
}
Примеры получения файлов изображения:
private Image getImage(String filename){
InputStream stream = null;
try {
stream = new FileInputStream(filename);
Image image = new Image(stream);
return image;
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return null;
}
private Image getImage()// для чтения из Resource
Class<?> clazz = HelloApplication.class;
InputStream input = clazz.getResourceAsStream("//" + filebegin + filebasename + current + fileext);
Image image = new Image(input);
return image;
} catch (Exception e) {
e.printStackTrace();
return null;
}