Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. package prj;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.File;
  5. import java.io.FileReader;
  6. import java.io.IOException;
  7. import java.util.Arrays;
  8.  
  9. public class ZaehleAllePrgsZeilenV1
  10. {
  11. static long countDirs = 0;
  12. static long countFiles = 0;
  13. static long fileSize = 0;
  14. static long countRecords = 0;
  15.  
  16. static String pfad = "C:\\Users\\HBRI185\\Documents\\OCA-Kurs\\OCJP8PI\\WS_TN03\\OCA1910";
  17. static String search = ".java";
  18.  
  19. public static void main(String[] args) throws IOException
  20. {
  21. System.out.println("Start");
  22.  
  23. listDir(new File(pfad), search);
  24.  
  25. System.out.println("------------------------------------------");
  26. System.out.println(countDirs + " Verzeichnisse durchsucht.");
  27. System.out.println("------------------------------------------");
  28. System.out.println(countFiles + " Dateien gefunden");
  29. System.out.println("------------------------------------------");
  30. System.out.println("Größe aller Dateien : " + fileSize + " Bytes");
  31. System.out.println("------------------------------------------");
  32. System.out.println("mit insgesamt : " + countRecords + " Datensätzen");
  33. System.out.println("------------------------------------------");
  34.  
  35. System.out.println("Ende");
  36.  
  37. }
  38.  
  39. public static void listDir(File fy, String suche) throws IOException {
  40. File[] fileArray = fy.listFiles();
  41. if (fileArray.length > 0)
  42. Arrays.sort(fileArray); {
  43. for (File fx : fileArray) {
  44. if (!fx.isHidden()) {
  45. if (fx.isDirectory()) {
  46. countDirs++;
  47. listDir(fx, suche);
  48. } else {
  49. if (fx.getName().toLowerCase().endsWith((suche).toLowerCase())) {
  50. fileSize += fx.length();
  51. countFiles++;
  52. dateiLesen(fx.getPath());
  53. }
  54. }
  55. }
  56. }
  57. }
  58. }
  59.  
  60. public static void dateiLesen(String dateiName) throws IOException {
  61. File f = new File(dateiName);
  62. FileReader fr = new FileReader(f);
  63. BufferedReader gzl = new BufferedReader(fr);
  64.  
  65. while (null != gzl.readLine()) {
  66. countRecords++;
  67. }
  68. gzl.close();
  69.  
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement