Name: Anonymous 2009-03-29 9:28
if you can write most of what's there, but more efficiently, in five minutes?
import java.util.*;
import java.io.*;
public class LineCounter {
private static final String basePath = "C:\\j2se\\src\\share\\classes";
private static final boolean filterComments = false;
private static BufferedReader br;
public static void main(String[] args) throws IOException {
File root = new File(basePath);
System.out.println("Total Lines of code: "+recursiveReadDir(root.listFiles()));
}
private static int recursiveReadDir(File[] files) throws IOException {
int locCount = 0;
for(int i=0; i<files.length; i++) {
if(files[i].isDirectory()) {
System.out.println(files[i]);
locCount+=recursiveReadDir(files[i].listFiles());
}
else {
locCount+=FileLOC(files[i]);
}
}
return locCount;
}
private static int FileLOC(File location) throws IOException {
br = new BufferedReader(new FileReader(location));
int count = 0;
int index = 0, index2 = 0;
String line = "";
boolean inComment = false;
while((line=br.readLine())!=null) {
if(filterComments) {
if((index=line.indexOf("/*"))>=0) inComment = true;
index2 = line.indexOf("*/");
if(index2>=0 && index2>=index) inComment = false;
}
if(!inComment) {
line=line.trim();
if(filterComments) if(line.length()<=2 || line.charAt(0)=='/' && line.charAt(1)=='/') continue;
count++;
}
}
br.close();
return count;
}
}
class Main {
public static void main(String[] args) {
String asd = "/*";
System.out.writeLn("hax my anus");
}
}