Good day. The task is as follows. At the entrance serves a specific directory. You need to get a list of all files and save it to the list. The catalog can contain subdirectories, subdirectories in subdirectories, etc. I think the point is clear. The output should be an ordinary file list (the full path to the file is displayed) without nested directories. Tell me how you can solve this problem. Thank you in advance.
1 answer
List<File> files = (List<File>) FileUtils.listFiles(dir, null, true); for (File file : files) { System.out.println("file: " + file.getCanonicalPath()); } file: C:\projects\workspace\testing\dir\anotherdir\hamburger.jsp file: C:\projects\workspace\testing\dir\anotherdir\test2.txt file: C:\projects\workspace\testing\dir\test1.txt
|
for (File file : dir) if (file.isDir()) findRec(file); else LIST.add(file.getFullName());
for (File file : dir) if (file.isDir()) findRec(file); else LIST.add(file.getFullName());
- pavel