Я использую эту функцию, чтобы определить, существует ли мой файл или нет. Хотя у меня есть изображение, хранящееся как .jpg,.JPG,.png и .PNG. Но он всегда возвращает .jpg или .png как истинный, даже если реальный файл имеет расширение .JPG или .PNG.
После того, как я отрисую его на мою веб-страницу, он выдает сообщение об ошибке "Не удалось загрузить ресурс: сервер ответил со статусом 404 (не найден)".
public static String getPhotoFileExtension(int empKey){
try{
String[] types = {".jpg",".JPG",".png", ".PNG"};
for(String t : types)
{
String path = "/"+Common.PHOTO_PATH + empKey + t;
File f = new File(Sessions.getCurrent().getWebApp()
.getRealPath(path));
if(f.isFile())
return t;
}
}catch (Exception e) {
e.printStackTrace();
}
return "";
}