Here is the complete code:
package de.xam.loc;Maybe one day this will end up in an Eclipse or Maven plugin ;-)
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public final class LOC {
public static void main(String[] args) throws IOException {
if (args.length == 0) {
System.out.println("Usage: LOC");
} else {
LOC loc = new LOC();
File root = new File(args[0]);
loc.countLinesOfCodeInDirectory(root);
System.out.println("Found " + loc.lines + " lines in " + loc.files
+ " files within " + root.getAbsolutePath());
}
}
private long files = 0;
private long lines = 0;
private void countLinesOfCodeInDirectory(File dir) throws IOException {
for (File f : dir.listFiles()) {
if (f.isDirectory()) {
countLinesOfCodeInDirectory(f);
} else {
if (f.getName().endsWith(".java")) {
BufferedReader br = new BufferedReader(new FileReader(f));
String line = br.readLine();
while (line != null) {
if (!line.trim().equals("")) {
this.lines++;
}
line = br.readLine();
}
br.close();
this.files++;
}
}
}
}
}
hey dude....thnx 4 ur LoC prog ...it helpd me to skip da starting wrk coz i still need to modify it...keep programming ...:D
ReplyDelete