@Test public void listFile() { String path = TestUtil.path + "/image"; List<File> list1 = FileHelper.listFile(new File(path)); list1.forEach(file -> System.out.println(file.getAbsolutePath())); System.out.println("=================="); List<File> list2 = FileHelper.listFileSuffix(new File(path), "jpg"); list2.forEach(file -> System.out.println(file.getAbsolutePath())); System.out.println("=================="); List<File> list3 = FileHelper.listFileName(new File(path), "1.jpg"); list3.forEach(file -> System.out.println(file.getAbsolutePath())); List<File> list4 = FileHelper.listFileNameIgnoreCase(new File(path), "1.jpg"); list4.forEach(file -> System.out.println(file.getAbsolutePath())); List<File> list5 = FileHelper.listFileFilter(new File(path), new ObjectFilter() { @Override public boolean filter(Object o) { File file = (File) o; return file.length() > 1024 * 200; } }); list5.forEach(file1 -> System.out.println(file1.getAbsolutePath())); System.out.println("=================="); path = TestUtil.path + "/text"; List<File> list = FileHelper.listFileNameReg(new File(path), Pattern.compile(".*\\.txt", Pattern.CASE_INSENSITIVE)); list.forEach(file -> System.out.println(file.getAbsolutePath())); System.out.println("=================="); FileHelper.listFileWithHandler(new File(path), new ObjectProcess<File, File>() { @Override public File process(File file) { String fileName = file.getAbsolutePath(); String md5 = FileHelper.fileHash(file, "MD5"); String suffix = FileHelper.suffix(file); String encoding = FileHelper.simpleEncoding(file); String encoding1 = FileImpl.guestFileEncoding(file); System.out.println(fileName + "\t" + md5 + "\t" + suffix + "\t" + encoding + "\t" + encoding1); return null; } }); }
public static List<File> listFile(File path) { List<File> list = new ArrayList<>(); if (path != null && path.exists() && path.isDirectory()) { File[] files = path.listFiles(); if (files == null || files.length == 0) { return list; } for (File file : files) { if (file.isDirectory()) { list.addAll(listFile(file)); } else { list.add(file); } } } return list; }
FileHelper { public static List<File> listFile(File path) { List<File> list = new ArrayList<>(); if (path != null && path.exists() && path.isDirectory()) { File[] files = path.listFiles(); if (files == null || files.length == 0) { return list; } for (File file : files) { if (file.isDirectory()) { list.addAll(listFile(file)); } else { list.add(file); } } } return list; } }
FileHelper { public static List<File> listFile(File path) { List<File> list = new ArrayList<>(); if (path != null && path.exists() && path.isDirectory()) { File[] files = path.listFiles(); if (files == null || files.length == 0) { return list; } for (File file : files) { if (file.isDirectory()) { list.addAll(listFile(file)); } else { list.add(file); } } } return list; }  }
FileHelper { public static List<File> listFile(File path) { List<File> list = new ArrayList<>(); if (path != null && path.exists() && path.isDirectory()) { File[] files = path.listFiles(); if (files == null || files.length == 0) { return list; } for (File file : files) { if (file.isDirectory()) { list.addAll(listFile(file)); } else { list.add(file); } } } return list; }  static void handlerWithLine(File file, String encoding, ObjectHandler<String> handler); static void processWithLine(File file, String encoding, Collection<E> result, ObjectProcess<String, E> process); static int lineCounts(File file); static List<String> readLines(File file); static List<String> readLines(File file, String encoding); static String readContents(File file); final static boolean createFiles(File file); final static boolean createFiles(File file, boolean isReNew); static boolean write(File file, String str); static boolean write(File file, String str, String encoding); static boolean addWrite(File file, String str); static boolean addWrite(File file, String str, String encoding); static boolean copy(File resource, File target); static boolean copyFile(File file, File targetFile); static boolean cleanFile(File file); static boolean delete(File file); static List<File> listFile(File path); static List<File> listFileSuffix(File dirPath, String postfixs); static List<File> listFileName(File dirPath, String fileName); static List<File> listFileNameIgnoreCase(File dirPath, String fileName); static List<File> listFileFilter(File path, ObjectFilter filter); static List<File> listFileNameReg(File dirPath, Pattern pattern); static List<File> listFileWithHandler(File path, ObjectProcess<File, File> handler); static boolean createFile(String path); static String suffix(File file); static String fileHash(File file, String HashTyle); static String simpleEncoding(File file); static boolean zipDeCompress(File file, String zipFile); static boolean zipUnCompress(File zipFile, String path); }
FileHelper { public static List<File> listFile(File path) { List<File> list = new ArrayList<>(); if (path != null && path.exists() && path.isDirectory()) { File[] files = path.listFiles(); if (files == null || files.length == 0) { return list; } for (File file : files) { if (file.isDirectory()) { list.addAll(listFile(file)); } else { list.add(file); } } } return list; }  static void handlerWithLine(File file, String encoding, ObjectHandler<String> handler); static void processWithLine(File file, String encoding, Collection<E> result, ObjectProcess<String, E> process); static int lineCounts(File file); static List<String> readLines(File file); static List<String> readLines(File file, String encoding); static String readContents(File file); final static boolean createFiles(File file); final static boolean createFiles(File file, boolean isReNew); static boolean write(File file, String str); static boolean write(File file, String str, String encoding); static boolean addWrite(File file, String str); static boolean addWrite(File file, String str, String encoding); static boolean copy(File resource, File target); static boolean copyFile(File file, File targetFile); static boolean cleanFile(File file); static boolean delete(File file); static List<File> listFile(File path); static List<File> listFileSuffix(File dirPath, String postfixs); static List<File> listFileName(File dirPath, String fileName); static List<File> listFileNameIgnoreCase(File dirPath, String fileName); static List<File> listFileFilter(File path, ObjectFilter filter); static List<File> listFileNameReg(File dirPath, Pattern pattern); static List<File> listFileWithHandler(File path, ObjectProcess<File, File> handler); static boolean createFile(String path); static String suffix(File file); static String fileHash(File file, String HashTyle); static String simpleEncoding(File file); static boolean zipDeCompress(File file, String zipFile); static boolean zipUnCompress(File zipFile, String path);  }