List of usage examples for java.io File listFiles
public File[] listFiles()
From source file:Main.java
private static void walkTreeAndReturnJARS(File dir, Collection<File> dst) { for (File e : dir.listFiles()) { if (e.isDirectory()) walkTreeAndReturnJARS(e, dst); else {//from w w w . java 2 s .c o m if (e.getName().toLowerCase().endsWith(".jar")) { dst.add(e); } } } }
From source file:Main.java
public static List<String> getFile(String path, Integer count, String fileEnd, List<String> result) { File f = new File(path); File[] files = f.listFiles(); for (File s : files) { if (s.isDirectory()) { getFile(s.getAbsolutePath(), count, fileEnd, result); } else {/* ww w . j a v a 2s .c o m*/ if (s.getName().toLowerCase().endsWith(fileEnd.toLowerCase())) { result.add(s.getAbsolutePath()); } } } return result; }
From source file:Main.java
public static void deleteFiles(String path, String name) { File sharedPrefsDir = new File(path); File[] files = sharedPrefsDir.listFiles(); for (File file : files) { if (file.getName().endsWith(name)) { file.delete();//from w w w . j a v a 2 s. c om } } }
From source file:Utils.java
private static void deleteContentsRecursive(File file) throws IOException { File[] files = file.listFiles(); for (File child : files) { if (child.isDirectory()) deleteContentsRecursive(child); if (!child.delete()) throw new IOException("Unable to delete " + child.getPath()); }//from w ww . ja va 2s .c om }
From source file:Main.java
/** * Look for the resource directory with raw beneath it. *//* w w w . j ava 2 s . c o m*/ private static File findResRawDir(File dir) { for (File file : dir.listFiles()) { if (file.getName().equals(RESOURCE_DIR_NAME) && file.isDirectory()) { File[] rawFiles = file.listFiles(new FileFilter() { public boolean accept(File file) { return file.getName().equals(RAW_DIR_NAME) && file.isDirectory(); } }); if (rawFiles.length == 1) { return rawFiles[0]; } } } return null; }
From source file:Main.java
public static long getFileSize(File f) { long size = 0; File files[] = f.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { size = size + getFileSize(files[i]); } else {/*from ww w . java2s.c om*/ size = size + files[i].length(); } } return size; }
From source file:Main.java
private static long getDirSize(File dir) { long size = 0; File[] files = dir.listFiles(); for (File file : files) { if (file.isFile()) { size += file.length();/*from w w w .j a v a 2 s. c o m*/ } } return size; }
From source file:Main.java
static void addDir(File dirObj, ZipOutputStream out) throws IOException { File[] files = dirObj.listFiles(); byte[] tmpBuf = new byte[1024]; for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { addDir(files[i], out);//w ww.j a va2 s . c o m continue; } FileInputStream in = new FileInputStream(files[i].getAbsolutePath()); System.out.println(" Adding: " + files[i].getAbsolutePath()); out.putNextEntry(new ZipEntry(files[i].getAbsolutePath())); int len; while ((len = in.read(tmpBuf)) > 0) { out.write(tmpBuf, 0, len); } out.closeEntry(); in.close(); } }
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 w w w . j a v a 2s. c o m 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:edu.uci.ics.asterix.test.aql.AQLTestSuite.java
public static Test suite() throws ParseException, UnsupportedEncodingException, FileNotFoundException { File testData = new File(AQLTS_PATH); File[] queries = testData.listFiles(); TestSuite testSuite = new TestSuite(); for (File file : queries) { if (file.isFile()) { testSuite.addTest(new AQLTestCase(file)); }/*from w w w. j a v a 2 s . c o m*/ } testData = new File(AQLTS_SQL_LIKE_PATH); queries = testData.listFiles(); for (File file : queries) { if (file.isFile()) { testSuite.addTest(new AQLTestCase(file)); } } return testSuite; }