Advertisement
superjorj

Untitled

Feb 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. package lab2;
  2.  
  3.  
  4. import java.util.*;
  5. import java.io.*;
  6.  
  7. class Parser
  8. {
  9.  
  10. public static void citeste(String fisier)
  11. {
  12. String buf= " ";
  13. int c;
  14. FileReader f = null;
  15. try
  16. {
  17. f = new FileReader(fisier);
  18. while ((c = f.read()) != -1)
  19. {
  20. buf = buf + (char)c;
  21. }
  22. f.close();
  23. }
  24. catch (FileNotFoundException e)
  25. {
  26. System.out.println("Fisierul nu a fost gasit");
  27. }
  28. catch (IOException e)
  29. {
  30. System.out.println("Eroare la citire");
  31. }
  32. }
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39. public static void getfiles(String file2)
  40. {
  41.  
  42. File folder = new File(file2);
  43. File[] listOfFiles = folder.listFiles();
  44.  
  45. for (File file : listOfFiles) {
  46. if (file.isFile()) {
  47. System.out.println(file.getName());
  48. }
  49.  
  50. else if(file.isDirectory()) {
  51. String name = file.getName();
  52. getfiles(file2+"/"+name);
  53. }
  54. }
  55. }
  56. public static void main(String argv[])
  57. {
  58.  
  59. String file="/home/student/Documents/api";
  60. getfiles(file);
  61.  
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement