List of usage examples for java.io File getName
public String getName()
From source file:cf.janga.hook.utils.IOUtils.java
public static boolean hasExtension(File file, String extension) { String fileName = file.getName(); return StringUtils.isNotBlank(fileName) && fileName.endsWith("." + extension) && file.isFile(); }
From source file:Main.java
public static List<File> getFiles(Context context, String ext) { File dir = context.getFilesDir(); final List<File> files = new ArrayList<File>(); File[] subFiles = dir.listFiles(); if (subFiles != null) { for (File file : subFiles) { if (file.isFile() && file.getName().endsWith(ext)) { files.add(file);/*w w w. j ava 2 s . c o m*/ } } } return files; }
From source file:Main.java
/** * Delete the earliest file in the specified directory * /*w w w .j ava2 s . c o m*/ * @param dir * The specified directory * @param exceptFile * Exclude the file name */ public static final void deleteEarliestFile(File dir, String exceptFile) { if (dir != null && dir.isDirectory()) { File earlyFile = null; File[] files = dir.listFiles(); if (files.length == 0) return; for (int i = 0; i < files.length; i++) { File f = files[i]; if (f.getName().equals(exceptFile)) continue; if (earlyFile == null) { earlyFile = files[i]; continue; } if (earlyFile.lastModified() > f.lastModified()) { earlyFile = f; } } if (earlyFile != null) earlyFile.delete(); } }
From source file:Main.java
public static File getFiles(String path, String fileName) { File f = new File(path); File[] files = f.listFiles(); if (files == null) { return null; }//from ww w.j av a 2 s . c om if (null != fileName && !"".equals(fileName)) { for (int i = 0; i < files.length; i++) { File file = files[i]; if (fileName.equals(file.getName())) { return file; } } } return null; }
From source file:com.book.identification.FileType.java
public static FileType valueOf(File file) { String extension = FilenameUtils.getExtension(file.getName()); return FileType.valueOf(extension.toUpperCase()); }
From source file:boa.BoaMain.java
protected static String jarToClassname(final File f) { String s = f.getName(); if (s.indexOf('.') != -1) s = s.substring(0, s.lastIndexOf('.')); return pascalCase(s); }
From source file:Main.java
public static File findParentDir(File file, String fileKey) { if (fileKey.equals(file.getName())) { return file; } else if (file.getParentFile() != null) { return findParentDir(file.getParentFile(), fileKey); } else {// www. j a v a 2s. c om return file.getParentFile(); } }
From source file:Main.java
/** * Get the extension of a file./*from w w w .j a va 2 s. com*/ */ public static String getExtension(File f) { String ext = null; String s = f.getName(); int i = s.lastIndexOf('.'); if (i > 0 && i < s.length() - 1) { ext = s.substring(i + 1).toLowerCase(); } return ext; }
From source file:Main.java
private static boolean isMusicFile(File file) { String extension = getExtension(file.getName()); return MUSIC_FILE_EXTENSIONS.contains(extension); }
From source file:Main.java
private static void deleteDirectorySync(File dir) { try {//from w ww .ja va 2s . co m File[] files = dir.listFiles(); if (files != null) { for (File file : files) { String fileName = file.getName(); if (!file.delete()) { Log.e(TAG, "Failed to remove " + file.getAbsolutePath()); } } } if (!dir.delete()) { Log.w(TAG, "Failed to remove " + dir.getAbsolutePath()); } return; } catch (Exception e) { Log.e(TAG, "Failed to remove old libs, ", e); } }