Datasets:
ArXiv:
License:
File size: 948 Bytes
c574d3a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
package rd222dv_assign1;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
public class PrintJavaMain {
public static void main(String[] args) {
File currentDirectory = new File("D:\\lnu\\java_courses\\1DV507\\src\\rd222dv_assign1"); // current directory
printAllJavaFiles(currentDirectory);
}
public static void printAllJavaFiles(File directory) {
try {
File[] files = directory.listFiles();
for (File file : files) {
if (file.isDirectory()) {
System.out.println("Directory: " + file.getCanonicalPath());
printAllJavaFiles(file);
} else {
int line = 0;
Scanner sc = new Scanner(file);
while(sc.hasNextLine()){
line++;
sc.nextLine();
}
sc.close();
System.out.println("File: " + file.getCanonicalPath() +" + Number of lines: "+line);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
|