List of usage examples for java.io File list
public String[] list()
From source file:eu.sisob.uma.restserver.TaskManager.java
/** * Return the task codes of a user//from w w w. ja va 2 s. c o m * * Is possible that use thee locker of AuthorizationManager * * @param user * @param pass * @return */ public static List<String> listTasks(String user, String pass) { List<String> results = new ArrayList<String>(); String result_code_task_folder = TASKS_USERS_PATH + File.separator + user; File result_file = new File(result_code_task_folder); if (result_file.exists()) { List<String> tasks_folders = Arrays.asList(result_file.list()); for (String folder : tasks_folders) { results.add(folder); } } else { } return results; }
From source file:com.dnielfe.manager.utils.SimpleUtils.java
@NotNull public static ArrayList<String> listFiles(String path) { ArrayList<String> mDirContent = new ArrayList<String>(); boolean showhidden = Settings.mShowHiddenFiles; if (!mDirContent.isEmpty()) mDirContent.clear();/* w w w . j a v a 2 s . c om*/ final File file = new File(path); if (file.exists() && file.canRead()) { String[] list = file.list(); int len = list.length; // add files/folder to ArrayList depending on hidden status for (int i = 0; i < len; i++) { if (!showhidden) { if (list[i].toString().charAt(0) != '.') mDirContent.add(path + "/" + list[i]); } else { mDirContent.add(path + "/" + list[i]); } } } else { try { mDirContent = RootCommands.listFiles(file.getAbsolutePath(), showhidden); } catch (Exception e) { e.printStackTrace(); } } // sort files with a comparator SortUtils.sortList(mDirContent, file.getPath()); return mDirContent; }
From source file:com.xxg.jdeploy.util.FileUtil.java
/** * //from www .jav a2 s.c o m * @param src * @param dest * @throws IOException */ public static void copyFolder(File src, File dest) throws IOException { if (src.isDirectory()) { if (!dest.exists()) { dest.mkdir(); } String files[] = src.list(); for (String file : files) { File srcFile = new File(src, file); File destFile = new File(dest, file); // copyFolder(srcFile, destFile); } } else { InputStream in = new FileInputStream(src); OutputStream out = new FileOutputStream(dest); byte[] buffer = new byte[1024]; int length; while ((length = in.read(buffer)) > 0) { out.write(buffer, 0, length); } in.close(); out.close(); } }
From source file:goja.initialize.ctxbox.ClassSearcher.java
/** * @param baseDirName //from w ww .ja va 2 s .co m * @param targetFileName ??? */ private static List<String> findFiles(String baseDirName, String targetFileName, final String classpath) { /** * ????? * ???? ?????? */ List<String> classFiles = Lists.newArrayList(); File baseDir = new File(baseDirName); if (!baseDir.exists() || !baseDir.isDirectory()) { LOG.error("search error" + baseDirName + "is not a dir?"); } else { String[] files = baseDir.list(); File file; String fileName, open = classpath + File.separator, close = ".class"; int start, end; for (String file_path : files) { file = new File(baseDirName + File.separator + file_path); if (file.isDirectory()) { classFiles .addAll(findFiles(baseDirName + File.separator + file_path, targetFileName, classpath)); } else { if (wildcardMatch(targetFileName, file.getName())) { fileName = file.getAbsolutePath(); start = fileName.indexOf(open); end = fileName.indexOf(close, start + open.length()); // window ,? String className = StringUtils.replace(fileName.substring(start + open.length(), end), File.separator, "."); classFiles.add(className); } } } } return classFiles; }
From source file:com.galenframework.javascript.GalenJsApi.java
public static String[] listDirectory(String dirPath) throws IOException { File file = new File(dirPath); if (!file.exists()) { throw new FileNotFoundException(dirPath); } else if (!file.isDirectory()) { throw new IOException("Not a directory: " + dirPath); }/*from w ww. j av a 2 s . c om*/ return file.list(); }
From source file:edu.unc.lib.dl.util.FileUtils.java
public static void copyFolder(File src, File dest) throws IOException { if (src.isDirectory()) { // if directory not exists, create it if (!dest.exists()) { dest.mkdir();/*from w ww.jav a2s . c o m*/ } // list all the directory contents String files[] = src.list(); for (String file : files) { // construct the src and dest file structure File srcFile = new File(src, file); File destFile = new File(dest, file); // recursive copy copyFolder(srcFile, destFile); } } else { // if file, then copy it // Use bytes stream to support all file types InputStream in = new FileInputStream(src); OutputStream out = new FileOutputStream(dest); byte[] buffer = new byte[1024]; int length; // copy the file content in bytes while ((length = in.read(buffer)) > 0) { out.write(buffer, 0, length); } in.close(); out.close(); } }
From source file:hudson.plugins.jobConfigHistory.JobConfigHistorySaveableListener.java
/** * Copy file from one location to another. * @param src file to copy from// w w w. ja va 2 s .com * @param dest file to copy to */ public static void copyFolder(File src, File dest) throws IOException { if (src.isDirectory()) { //if directory not exists, create it if (!dest.exists()) { dest.mkdir(); } //list all the directory contents String files[] = src.list(); for (String file : files) { //construct the src and dest file structure File srcFile = new File(src, file); File destFile = new File(dest, file); //recursive copy copyFolder(srcFile, destFile); } } else { //if file, then copy it //Use bytes stream to support all file types if (!dest.exists()) { InputStream in = new FileInputStream(src); OutputStream out = new FileOutputStream(dest); byte[] buffer = new byte[1024]; int length; //copy the file content in bytes while ((length = in.read(buffer)) > 0) { out.write(buffer, 0, length); } in.close(); out.close(); } } }
From source file:com.ushahidi.android.app.util.Util.java
/** * Delete content of a folder recursively. * //from www . j a v a 2 s . c o m * @param String path - path to the directory. * @return void */ public static void rmDir(String path) { File dir = new File(path); if (dir.isDirectory()) { String[] children = dir.list(); Log.d("Directory", "dir.list returned some files" + children.length + "--"); for (int i = 0; i < children.length; i++) { File temp = new File(dir, children[i]); if (temp.isDirectory()) { rmDir(temp.getName()); } else { temp.delete(); } } dir.delete(); } else { Log.d("Directory", "This is not a directory" + path); } }
From source file:com.anjalimacwan.fragment.NoteListFragment.java
private static String[] getListOfNotes(File file) { return file.list(); }
From source file:com.github.blindpirate.gogradle.util.IOUtils.java
public static boolean dirIsEmpty(File directory) { if (!directory.exists()) { return true; }// ww w. j ava 2 s .c om String[] files = Assert.isNotNull(directory.list()); return files.length == 0; }