Here you can find the source of getFiles(String path)
Parameter | Description |
---|---|
path | a parameter |
public static List<File> getFiles(String path)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Main { /**// ww w . j a v a 2 s . c o m * getFiles * * @param path * @return */ public static List<File> getFiles(String path) { File dir = new File(path); if (dir.exists()) { File[] files = dir.listFiles(); if (files != null && files.length > 0) { return initDirs(files); } } return Collections.emptyList(); } /** * existFile * * @param path * @return */ public static boolean exists(String path) { try { File temp = new File(path); return temp.exists(); } catch (Exception e) { // ignore } return false; } public static List<File> initDirs(File[] files) { ArrayList<File> dirs = new ArrayList<File>(); for (int i = 0; i < files.length; i++) { if (files[i].isFile() || files[i].isDirectory()) { dirs.add(files[i]); } } return dirs; } /** * isFile * * @param path * @return */ public static boolean isFile(String path) { File file = new File(path); if (file.exists() && file.isFile()) { return true; } return false; } }