@Test public void testGetFileList() { List<File> files = FileUtil.getFileList("D:\\lvji_git\\lvji-codes\\templates\\java\\guide"); files.stream().forEach(item -> { System.out.println("name is " + item.getName()); String relativePath = FileUtil.getRelativePath("D:\\lvji_git\\lvji-codes\\templates\\java\\guide", item.getAbsolutePath()); if (relativePath.contains("\\")) { System.out.println("relative path is " + relativePath.substring(0, relativePath.lastIndexOf("\\"))); } else { System.out.println("relative path is " + relativePath); } }); }
public static List<File> getFileList(String path) { List<File> list = new ArrayList<>(); File dir = new File(path); File[] files = dir.listFiles(); if (files != null) { for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { list.addAll(getFileList(files[i].getAbsolutePath())); } else { list.add(files[i]); } } } return list; }
FileUtil { public static List<File> getFileList(String path) { List<File> list = new ArrayList<>(); File dir = new File(path); File[] files = dir.listFiles(); if (files != null) { for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { list.addAll(getFileList(files[i].getAbsolutePath())); } else { list.add(files[i]); } } } return list; } }
FileUtil { public static List<File> getFileList(String path) { List<File> list = new ArrayList<>(); File dir = new File(path); File[] files = dir.listFiles(); if (files != null) { for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { list.addAll(getFileList(files[i].getAbsolutePath())); } else { list.add(files[i]); } } } return list; }  }
FileUtil { public static List<File> getFileList(String path) { List<File> list = new ArrayList<>(); File dir = new File(path); File[] files = dir.listFiles(); if (files != null) { for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { list.addAll(getFileList(files[i].getAbsolutePath())); } else { list.add(files[i]); } } } return list; }  static void copyDir(String sourcePath, String targetPath); static List<File> getFileList(String path); static String getRelativePath(String sourcePath, String targetPath); }
FileUtil { public static List<File> getFileList(String path) { List<File> list = new ArrayList<>(); File dir = new File(path); File[] files = dir.listFiles(); if (files != null) { for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { list.addAll(getFileList(files[i].getAbsolutePath())); } else { list.add(files[i]); } } } return list; }  static void copyDir(String sourcePath, String targetPath); static List<File> getFileList(String path); static String getRelativePath(String sourcePath, String targetPath);  }