Iterate over a files in a directory


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  1. package com.asset.jupiter.testing.testEJB;
  2.  
  3.  
  4.  
  5.  
  6. import java.io.File;
  7. /**
  8.  * @Author:Khaled Talaat
  9.  */
  10. public class FilesReader {
  11.  
  12. public FilesReader() {
  13. }
  14.  
  15. public static void main(String[] args){
  16. FilesReader filesReader = new FilesReader();
  17. String path = "D:\\Jupiter\\Documentation\\Core\\samples";
  18. filesReader.searchFolders(new File(path));
  19. System.out.println("Done");
  20. }
  21.  
  22. public void searchFolders(File file) {
  23. if(file.isDirectory()){
  24. String internalNames[] = file.list();
  25. for(int i=0; i<internalNames.length; i++){
  26. searchFolders(new File(file.getAbsolutePath() + "\\" + internalNames[i]));
  27. }
  28. } else {
  29. String[] splitted = file.getName().split(".java");
  30. System.out.println(splitted[0]);
  31. }
  32. }
  33. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.