Advertisement
Guest User

Untitled

a guest
Jun 25th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. public class Solution {
  2.  
  3.  
  4. public static List<String> getFileTree(String root) throws IOException {
  5.  
  6. List<String> result = new ArrayList<>();
  7. List<File> files = new ArrayList<>();
  8.  
  9. files.add(new File(root));
  10.  
  11. for(File xx : files)
  12. {
  13. File current = xx;
  14. if(current.isDirectory())
  15. {
  16.  
  17. for(File f : current.listFiles())
  18. {
  19. files.add(f);
  20. }
  21. }
  22. if(current.isFile())
  23. {
  24. result.add(current.getAbsolutePath());
  25. }
  26. }
  27.  
  28. return result;
  29. }
  30.  
  31.  
  32.  
  33.  
  34. public static void main(String[] args) {
  35. List<String> fileList = null;
  36. try {
  37. fileList = getFileTree("C:\\path");
  38. } catch (IOException e) {
  39. e.printStackTrace();
  40. }
  41. for (String filePath : fileList)
  42. System.out.println(filePath);
  43.  
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement