java 統計代碼行數

女朋友回家了,作爲一個無聊的宅男只能自娛自樂,寫點代碼統計下我寫過多少代碼,結果有點失望,沒有想象中的上百萬行-_-


package org.yeshen;

import java.io.BufferedReader;  
import java.io.File;  
import java.io.FileInputStream;  
import java.io.IOException;  
import java.io.InputStreamReader;  


public class CodeCounter {
	static long CodeLine = 0;

    public static void main(String[] args) { 

        File srcDir = new File("/home/yeshen/Documents/Folder/cmsmanager"); 

        if(!srcDir.isDirectory()){  
            return;  
        }  
        File[] fs = srcDir.listFiles();  

        try {  
            new CodeCounter().Counter(fs);  
        } catch (IOException e) {  
            e.printStackTrace();  
        }
        System.out.print("CodeLine:");
        System.out.print(CodeLine);
    }  

    public CodeCounter(){}

    private void Counter(File[] fs) throws IOException {  
        for(File file:fs){  
            if(!file.isDirectory() ){  
                if(file.getName().contains("java")){
                    File p =new File( file.getParent());
                    if(!p.exists()){p.mkdirs();}
                    BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file),"gbk")); 
                    String line = br.readLine();
                    while(line != null){
                    	if(line.trim().length() > 0){
                    		CodeLine ++;  		
                    	}
                    	line = br.readLine();
                    }
                    br.close();
                }
            }else{  
            	Counter(file.listFiles());  
            }  
        }  
    }  

}  


你可能感兴趣的:(java 統計代碼行數)