统计代码行数

方法1: 

       

  1. 使用Eclipse可以方便的统计工程或文件的代码行数。   
  2. 方法如下:   
  3. 1.在菜单栏点击Search,然后点击File...   
  4. 2.选中正则表达式(Regular expression),并在搜索文本框输入\n   
  5. 3.在文件名中输入*或*.java   
  6. 4.在范围里选中Enclosing projects   
  7. 5.在Search窗口就会显示出项目或文件的代码行数 

方法2:

 

public class ItemCount 
{ 
 private int lineCount; 
 private int fileCount; 
 public int getLineCount() 
 { 
 return lineCount; 
 } 
 public int getFileCount() 
 { 
 return fileCount; 
 } 
  
 public static void main(String[] args) throws IOException 
 { 
 ItemCount itemCount = new ItemCount(); 
 //path的值就是你的项目路径 
 String path = "E:\\lucene\\src"; 
 itemCount.getItemLineNum(new File(path)); 
 System.out.println("该项目一共有"+itemCount.getFileCount()+"个java源文件,"+itemCount.getLineCount()+"行代码"); 
 } 
   
 //递归 
 public void getItemLineNum(File path) throws IOException{ 
 if(path.isFile() && path.getName().endsWith(".java")){ 
 BufferedReader br = new BufferedReader(new FileReader(path)); 
 fileCount++; 
 while(br.readLine()!=null){ 
 lineCount++; 
 } 
 System.out.println(path.getName()); 
 br.close(); 
 }else if(path.isDirectory()){ 
 File[] listFiles = path.listFiles(); 
 for (File file : listFiles) 
 { 
 getItemLineNum(file); 
 } 
 } 
 } 
} 


 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值