List of usage examples for java.io File list
public String[] list()
From source file:com.github.ipaas.ifw.front.FisResource.java
private static void registerAll(String resMappingFileDir) throws FisException { String configDirPath = FisResource.class.getClassLoader().getResource(resMappingFileDir).getFile(); File mapJsonDir = new File(configDirPath); String[] mapJsonFiles = mapJsonDir.list(); FilenameFilter defaultFileNameFilter = new FilenameFilter() { public boolean accept(File dir, String name) { boolean isMatch = name.equals(DEFAULT_RES_MAPPING_FILE); return isMatch; }// w ww. j a v a 2 s.com }; FilenameFilter nameSpaceFileNameFilter = new FilenameFilter() { public boolean accept(File dir, String name) { boolean isMatch = name.endsWith("-" + DEFAULT_RES_MAPPING_FILE); return isMatch; } }; String[] childrenFileNames = mapJsonDir.list(defaultFileNameFilter); String[] nameSpacechildrenFileNames = mapJsonDir.list(nameSpaceFileNameFilter); if ((null == childrenFileNames || 0 == childrenFileNames.length) && (null == nameSpacechildrenFileNames || 0 == nameSpacechildrenFileNames.length)) { throw new FisException("Resource Mapping File Not Found!"); } // ? if (null != childrenFileNames || 0 < childrenFileNames.length) { for (int i = 0; i < childrenFileNames.length; i++) { FisResource.register(FisResource.DEFAULT_MAPPING_FILE_DIR, FisResource.DEFAULT_NS_GLOBAL); } } // ??? if (null != nameSpacechildrenFileNames || 0 < nameSpacechildrenFileNames.length) { for (int i = 0; i < nameSpacechildrenFileNames.length; i++) { String fileName = nameSpacechildrenFileNames[i]; int pos = fileName.indexOf("-" + FisResource.DEFAULT_RES_MAPPING_FILE); String namespace = fileName.substring(0, pos); FisResource.register(FisResource.DEFAULT_MAPPING_FILE_DIR, namespace); } } // for (int i = 0, len = mapJsonFiles.length; i < len; i++) { // String fileName = mapJsonFiles[i]; // if (fileName.equals(FisResource.DEFAULT_RES_MAPPING_FILE)) { // FisResource.register(FisResource.DEFAULT_MAPPING_FILE_DIR, // FisResource.DEFAULT_NS_GLOBAL); // } else { // int pos = fileName.indexOf("-" + // FisResource.DEFAULT_RES_MAPPING_FILE); // if (pos > 0) { // String namespace = fileName.substring(0, pos); // FisResource.register(FisResource.DEFAULT_MAPPING_FILE_DIR, // namespace); // } // } // } }
From source file:com.data.pack.Util.java
public static boolean deleteDir(java.io.File dir) { if (dir != null && dir.isDirectory()) { String[] children = dir.list(); for (int i = 0; i < children.length; i++) { boolean success = deleteDir(new File(dir, children[i])); if (!success) { return false; }//from w w w. j a va2 s . c o m } } // The directory is now empty so delete it return dir.delete(); }
From source file:IOUtilities.java
/** * Removes the given directory and all files within it, recursively. Returns * <code>true</code> if successful, <code>false</code> otherwise. Note that if * it return <code>false</code>, some (or all) the files in the directory may * already be deleted.// ww w .j a va2s . c o m */ public static boolean rmdir(File dir) { if (!dir.isDirectory()) throw new IllegalArgumentException(); String[] filenames = dir.list(); for (int i = 0; i < filenames.length; i++) { File file = new File(dir, filenames[i]); if (file.isDirectory()) { if (!rmdir(file)) return false; } else if (!file.delete()) return false; } return dir.delete(); }
From source file:com.blackberry.logtools.LogTools.java
public static void delete(File file) throws IOException { if (file.isDirectory()) { //directory is empty, then delete it if (file.list().length == 0) { file.delete();/*from w ww . j a va2s . c o m*/ } else { //list all the directory contents String files[] = file.list(); for (String temp : files) { //construct the file structure File fileDelete = new File(file, temp); //recursive delete delete(fileDelete); } //check the directory again, if empty then delete it if (file.list().length == 0) { file.delete(); } } } else { //if file, then delete it file.delete(); } }
From source file:com.dnielfe.manager.utils.SimpleUtils.java
public static void deleteTarget(Activity activity, String path, String dir) { File target = new File(path); if (!target.exists()) { return;// w ww .j a v a2s. co m } else if (target.isFile() && target.canWrite()) { target.delete(); requestMediaScanner(activity, target); return; } else if (target.isDirectory() && target.canRead()) { String[] file_list = target.list(); if (file_list != null && file_list.length == 0) { target.delete(); return; } else if (file_list != null && file_list.length > 0) { for (int i = 0; i < file_list.length; i++) { File temp_f = new File(target.getAbsolutePath() + "/" + file_list[i]); if (temp_f.isDirectory()) deleteTarget(activity, temp_f.getAbsolutePath(), dir); else if (temp_f.isFile()) { temp_f.delete(); requestMediaScanner(activity, temp_f); } } } if (target.exists()) if (target.delete()) return; } else if (target.exists() && !target.delete()) { RootCommands.DeleteFileRoot(path, dir); } return; }
From source file:Main.java
/** * @param filter -// ww w . ja va 2 s. c om * array of names to not copy. */ public static boolean copyDirectory(File from, File to, byte[] buffer, String[] filter) { // // System.out.println("copyDirectory("+from+","+to+")"); if (from == null) return false; if (!from.exists()) return true; if (!from.isDirectory()) return false; if (to.exists()) { // System.out.println(to + " exists"); return false; } if (!to.mkdirs()) { // System.out.println("can't make" + to); return false; } String[] list = from.list(); // Some JVMs return null for File.list() when the // directory is empty. if (list != null) { if (buffer == null) buffer = new byte[BUFFER_SIZE]; // reuse this buffer to copy files nextFile: for (int i = 0; i < list.length; i++) { String fileName = list[i]; if (filter != null) { for (int j = 0; j < filter.length; j++) { if (fileName.equals(filter[j])) continue nextFile; } } File entry = new File(from, fileName); // System.out.println("\tcopying entry " + entry); if (entry.isDirectory()) { if (!copyDirectory(entry, new File(to, fileName), buffer, filter)) return false; } else { if (!copyFile(entry, new File(to, fileName), buffer)) return false; } } } return true; }
From source file:net.openchrom.xxd.processor.supplier.rscripting.ui.code.RServe.java
public static File[] ListFilesDirectory(File filedirectory, final String[] extensions) { File dir = filedirectory; String[] children = dir.list(); if (children == null) { } else {//from w w w . ja v a 2s . co m for (int i = 0; i < children.length; i++) { // Get filename of the file or directory inside Plugin. String filename = children[i]; } } // Filter the extension of the file. FilenameFilter filter = new FilenameFilter() { public boolean accept(File dir, String name) { return (name.endsWith(extensions[0]) || name.endsWith(extensions[1]) || name.endsWith(extensions[2]) || name.endsWith(extensions[3]) || name.endsWith(extensions[4]) || name.endsWith(extensions[5])); } }; File[] files = dir.listFiles(filter); /* Sort the filenames! */ Arrays.sort(files, NameFileComparator.NAME_INSENSITIVE_COMPARATOR); return files; }
From source file:gov.nih.nci.restgen.util.GeneratorUtil.java
public static void copyFiles(String srcFolderStr, String destFolderStr, List exclude) throws IOException { File srcFolder = new File(srcFolderStr); File destFolder = new File(destFolderStr); if (srcFolder.isDirectory()) { // if directory not exists, create it if (!destFolder.exists()) { destFolder.mkdir();/*from w w w .jav a2s . c o m*/ //System.out.println("Directory copied from " + srcFolder + " to " + destFolder); } String files[] = srcFolder.list(); for (String file : files) { File srcFile = new File(srcFolder, file); if (exclude != null && exclude.contains(srcFile.getName())) continue; File destFile = new File(destFolder, file); copyFile(srcFile, destFile); } } }
From source file:com.glaf.core.util.ZipUtils.java
public static void makeZip(File dir, File zipFile) throws IOException, FileNotFoundException { JarOutputStream jos = new JarOutputStream(new FileOutputStream(zipFile)); String as[] = dir.list(); if (as != null) { for (int i = 0; i < as.length; i++) recurseFiles(jos, new File(dir, as[i]), ""); }// w ww . j ava 2 s.c o m jos.close(); }
From source file:org.mule.providers.soap.axis.wsdl.wsrf.util.AdviceAdderHelper.java
/** * list Classes inside a given package./* w w w . j a va 2 s . c om*/ * * @param pckgname String name of a Package, EG "java.lang" * @return Class[] classes inside the root of the given package * @throws ClassNotFoundException if the Package is invalid */ private static Class[] getClasses(String pckgname) throws ClassNotFoundException { ArrayList classes = new ArrayList(); // Get a File object for the package File directory = null; try { URL str = Thread.currentThread().getContextClassLoader().getResource(pckgname.replace('.', '/')); System.out.println("instance advice..." + new File(str.getFile()).getName()); directory = new File(str.getFile()); } catch (NullPointerException x) { throw new ClassNotFoundException(pckgname + " does not appear to be a valid package"); } if (directory.exists()) { // Get the list of the files contained in the package String[] files = directory.list(); for (int i = 0; i < files.length; i++) { // we are only interested in *Advice.class files if (files[i].endsWith("Advice.class")) { // removes the .class extension classes.add(Class.forName( pckgname + '.' + files[i].substring(0, files[i].length() - SUFFIX_CLASS_LENGTH))); } } } else { throw new ClassNotFoundException(pckgname + " does not appear to be a valid package"); } Class[] classesA = new Class[classes.size()]; classes.toArray(classesA); return classesA; }