private static File decodeFileURL(URL fileURL) { if(fileURL != null) { File file = new File(fileURL.getFile()); if(isExistingFile(file)) return file; file = new File(URLDecoder.decode(fileURL.getFile())); if(isExistingFile(file)) return file; } return null; }
private static File decodeFileURL(URL fileURL) { if(fileURL != null) { File file = new File(fileURL.getFile()); if(isExistingFile(file)) return file; file = new File(URLDecoder.decode(fileURL.getFile())); if(isExistingFile(file)) return file; } return null; }
/** * Tries to open the file from its absolute or relative path. If the file * doesn't exist, tries to load the file with <code>getResource</code>. * Throws a <code>FileNotFoundException</code> if the file cannot be found. * @param fileName the file name * @return the file as reader * @throws FileNotFoundException if the cannot be found */ public static File findFile(String fileName) throws FileNotFoundException { File file = new File(fileName); if(isExistingFile(file)) return file; fileName = fileName.replace('\\', '/'); file = new File(fileName); if(isExistingFile(file)) return file; URL fileURL = FileUtil.class.getClassLoader().getResource(fileName); file = decodeFileURL(fileURL); if(null != file) return file; fileURL = FileUtil.class.getResource(fileName); file = decodeFileURL(fileURL); if(null != file) return file; throw new FileNotFoundException("Could not find file: " + fileName); }
/** * Tries to open the file from its absolute or relative path. If the file * doesn't exist, tries to load the file with <code>getResource</code>. * Throws a <code>FileNotFoundException</code> if the file cannot be found. * @param fileName the file name * @return the file as reader * @throws FileNotFoundException if the cannot be found */ public static File findFile(String fileName) throws FileNotFoundException { File file = new File(fileName); if(isExistingFile(file)) return file; fileName = fileName.replace('\\', '/'); file = new File(fileName); if(isExistingFile(file)) return file; URL fileURL = FileUtil.class.getClassLoader().getResource(fileName); file = decodeFileURL(fileURL); if(null != file) return file; fileURL = FileUtil.class.getResource(fileName); file = decodeFileURL(fileURL); if(null != file) return file; throw new FileNotFoundException("Could not find file: " + fileName); }