如何计算一个JAVAEE项目一共多少行代码

如何计算一个JAVAEE项目一共多少行代码

看到你这个问题,感觉蛮有意思的,所以写了个递归方法,可以计算出项目有多少行代码

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);
}
}
}
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-06-26
对eclipse中编写代码框的左边有颜色的阴影部分右击,将show line number打钩追问

整个项目一共有多少行

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网