-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountFileLine.java
More file actions
53 lines (40 loc) · 1.01 KB
/
CountFileLine.java
File metadata and controls
53 lines (40 loc) · 1.01 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
*
*/
package filesIO;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
/**
* @author rutpatel
*
*/
public class CountFileLine {
private static int totalFileLine = 0;
public static void main(String[] args) throws IOException {
File file = new File("/Users/rutpatel/Documents/Rut/Collabera_JuMP/SpringTool_Workspace/BasicJava/src");
if (file.exists()) {
printDirectory(file);
}
System.out.println("\nTotal Lines in file - " + totalFileLine);
}
private static void printDirectory(File folder) throws IOException {
for (File file : folder.listFiles()) {
if (file.isDirectory()) {
printDirectory(file);
} else {
int tempCount = 0;
BufferedReader br = new BufferedReader(new FileReader(file));
if (file.getName().endsWith(".java")) {
while (br.readLine() != null) {
tempCount++;
}
}
br.close();
totalFileLine += tempCount;
System.out.println(file.getName() + " - " + tempCount);
}
}
}
}