List of usage examples for java.io File isDirectory
public boolean isDirectory()
From source file:Main.java
public static int getNumOfFiles(String dirPath) { File dir = new File(dirPath); if (!dir.isDirectory()) { return 0; }// w ww .j a v a 2 s.c o m File[] files = dir.listFiles(); int numOfFiles = 0; for (File f : files) { if (f.isFile()) { numOfFiles++; } } return numOfFiles; }
From source file:Main.java
public static boolean isDirectory(File file) { return file.exists() && file.isDirectory(); }
From source file:Main.java
/** * Recursively deletes folder and files. * //w w w . j a v a2s.c om * @param folder */ private static void delete(File folder) { File[] files = folder.listFiles(); for (int i = 0; i < files.length; i++) { File file = files[i]; if (file.isDirectory()) { delete(file); } file.delete(); } folder.delete(); }
From source file:Main.java
public static boolean mkdir(String path) { File file = new File(path); if (file.exists() && file.isDirectory()) { return true; }// w w w. j a v a 2 s . c o m file.mkdirs(); return true; }
From source file:Main.java
public static void deleteDirContent(File dir) { final File[] files = dir.listFiles(); if (files != null) { for (final File file : files) { if (file.isDirectory()) { deleteDirContent(file);// w w w . j ava2 s . c o m } file.delete(); } } }
From source file:Main.java
public static OutputStream getOutputStream(File dir, String fileName) throws Exception { File outFile = new File(dir, fileName); // as this could be dir=.../maps fileName=preview/file.jpg // we need to make sure the preview dir exists, and if it does not, we must make it File parent = outFile.getParentFile(); if (!parent.isDirectory() && !parent.mkdirs()) { // if it does not exist and i cant make it throw new RuntimeException("can not create dir " + parent); }//from www . j a va 2 s . c om return new FileOutputStream(outFile); }
From source file:Main.java
public static void deleteDirectory(File directory) { if (directory.exists()) { File[] files = directory.listFiles(); if (files != null) { for (File file : files) { if (file.isDirectory()) { deleteDirectory(file); } else { file.delete();/*from w w w . ja va 2s .c o m*/ } } } } directory.delete(); }
From source file:Main.java
public static boolean createDirs(String dirPath) { File file = new File(dirPath); if (!file.exists() || !file.isDirectory()) { return file.mkdirs(); }//from w w w . j ava 2 s .co m return true; }
From source file:Main.java
public static boolean checkFile(File f) { if (f != null && f.exists() && f.canRead() && (f.isDirectory() || (f.isFile() && f.length() > 0))) { return true; }//from ww w . j a v a 2s . co m return false; }
From source file:Main.java
public static void deleteFiles(String relativePath) { // File dir = new File(path); File dir = creatSDDir(relativePath); if (dir.isDirectory()) { File[] files = dir.listFiles(); for (File file : files) { file.delete();/*from w w w . j a v a 2 s . c o m*/ } } }