Last active
September 21, 2018 03:01
-
-
Save 0xWOF/af3040d98c873283b876 to your computer and use it in GitHub Desktop.
ProjectLineCounter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
따봉