List of usage examples for java.io File isDirectory
public boolean isDirectory()
From source file:Main.java
public static boolean canListFiles(File f) { try {/*from ww w . ja va2s . co m*/ return f.canRead() && f.isDirectory(); } catch (Exception e) { return false; } }
From source file:Main.java
private static void searchDirSort(File dirFile) { File[] files = dirFile.listFiles(); List<File> dirList = new ArrayList<File>(); if (files != null) { for (File file : files) { if (file.isDirectory()) { dirList.add(file);//from www.j a v a 2 s . c o m } else { if (file.getName().toLowerCase().contains(fileType.toLowerCase())) { listFile.add(file); } } } for (File dir : dirList) { if (dir.getName().subSequence(0, 1).equals(".") || dir.getName().equals("Android")) { } else { searchDirSort(dir); } } } }
From source file:Main.java
public static void copyFile(File src, File dst) throws IOException { if (src.isDirectory()) throw new IOException("Source is a directory"); InputStream in = new FileInputStream(src); OutputStream out = new FileOutputStream(dst); // Transfer bytes from in to out byte[] buf = new byte[1024]; int len;/*w w w . java 2 s . c o m*/ while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); }
From source file:Main.java
/** * Creates a FileFilter for a specified description * and an array of allowed extensions. <br /> * // w ww. ja v a 2s.c om * @param extensions the allowed extensions without a dot * @param description the displayed description * @return the created FileFilter */ public static FileFilter createFilter(final String[] extensions, final String description) { return new FileFilter() { @Override public boolean accept(File file) { if (file.isDirectory()) { return true; } String name = file.getName().toLowerCase(); for (String e : extensions) { if (name.endsWith("." + e.toLowerCase())) { return true; } } return false; } @Override public String getDescription() { return description; } }; }
From source file:Main.java
public static File getSaveMapDir() { if (mapsDir != null) { return mapsDir; }/* w ww. j a v a 2 s. c o m*/ File userHome = new File(System.getProperty("user.home")); File userMaps = new File(userHome, "maps"); if (!userMaps.isDirectory() && !userMaps.mkdirs()) { // if it does not exist and i cant make it throw new RuntimeException("can not create dir " + userMaps); } mapsDir = userMaps; return userMaps; }
From source file:Main.java
private static boolean isFolderAvailable(String epubFileName) { File file = new File(getFolioEpubFolderPath(epubFileName)); return file.isDirectory(); }
From source file:Main.java
/** * Get files of directory you passed. The files contains files of passed directory's sub directory by recursive exploring. *//* www . ja va2 s. co m*/ public static List<File> getAllFiles(File directory) { final List<File> fileList = new LinkedList<File>(); final File[] files = directory.listFiles(); if (files == null) return fileList; for (File file : files) { if (file.isDirectory()) fileList.addAll(getAllFiles(file)); else fileList.add(file); } return fileList; }
From source file:Main.java
public static File createDir(String dirPath) { File dirFile = new File(dirPath); if (!dirFile.exists() || !dirFile.isDirectory()) { boolean success = dirFile.mkdirs(); if (!success) { return null; }//from w w w. j ava 2 s . com } return dirFile; }
From source file:com.fluke.application.IEODReader.java
static void processChildren(File[] files, List<File> newFolders) throws IOException { for (File file : files) { if (file.isDirectory()) { newFolders.add(file);//w w w.ja v a2s . c om } else { processFile(file); } } }
From source file:Main.java
public static boolean delSDFile(String filePath) { File file = new File(filePath); if (file == null || !file.exists() || file.isDirectory()) return false; file.delete();// w ww .j a v a2 s . c o m return true; }