Skip to content

Instantly share code, notes, and snippets.

@0xWOF
Last active September 21, 2018 03:01
Show Gist options
  • Save 0xWOF/af3040d98c873283b876 to your computer and use it in GitHub Desktop.
Save 0xWOF/af3040d98c873283b876 to your computer and use it in GitHub Desktop.
ProjectLineCounter.java
import java.io.*;
/**
* Created by WOF on 2015. 11. 2..
*/
public class LineCounter {
public static void main(String[] args) throws IOException {
String path = "/Users/wof/develop/BandiSmart";
File folder = new File(path);
int result = getLinesFromFolder(folder);
System.out.println("sum : " + result);
}
public static int getLinesFromFolder(File folder) throws IOException {
int result = 0;
for(File file : folder.listFiles()) {
if(file.isDirectory())
result += getLinesFromFolder(file);
else
result += getLinesFromFile(file);
}
return result;
}
public static int getLinesFromFile(File file) throws IOException {
String file_name = file.getName();
if(file_name.lastIndexOf(".") == -1)
return 0;
String extension = file_name.substring(file_name.lastIndexOf("."), file_name.length());
if( !(extension.equals(".java") || extension.equals(".cpp") || extension.equals(".go") || extension.equals(".html") || extension.equals(".css")) )
return 0;
if(file_name.equals("R.java"))
return 0;
BufferedReader br = new BufferedReader(new FileReader(file));
int result = 0;
while(br.readLine() != null)
result += 1;
System.out.println(file.getName() + " : " + result);
return result;
}
}
@byeongsu-hong
Copy link

따봉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment