Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Solution {
- public static List<String> getFileTree(String root) throws IOException {
- List<String> result = new ArrayList<>();
- List<File> files = new ArrayList<>();
- files.add(new File(root));
- for(File xx : files)
- {
- File current = xx;
- if(current.isDirectory())
- {
- for(File f : current.listFiles())
- {
- files.add(f);
- }
- }
- if(current.isFile())
- {
- result.add(current.getAbsolutePath());
- }
- }
- return result;
- }
- public static void main(String[] args) {
- List<String> fileList = null;
- try {
- fileList = getFileTree("C:\\path");
- } catch (IOException e) {
- e.printStackTrace();
- }
- for (String filePath : fileList)
- System.out.println(filePath);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement