|
精华帖 (0) :: 良好帖 (0) :: 新手帖 (5) :: 隐藏帖 (0)
|
|
|---|---|
| 作者 | 正文 |
|
时间:2008-05-04
robbin 写道 你这样也忒麻烦了,我一行shell命令就搞定了:
find . -type f -iname "*.java" -exec cat {} \; | wc -l
像你那么兴师动众写一大陀Java代码真是画蛇添足。 BTW: wc *.java是不行滴,要加 -l 参数,还不能遍历子目录 lz都说是学习了,我觉得我们应该focus在他的代码有什么问题上。 如果lz的题目是怎么最快统计代码行数,你这个solution才是比较合理的reply。 |
|
| 返回顶楼 | |
|
时间:2008-05-04
我这儿运行你这个程序怎么这么慢的。。。。
|
|
| 返回顶楼 | |
|
时间:2008-05-04
Practiline Source Code Line Counter
|
|
| 返回顶楼 | |
|
时间:2008-05-04
re:anlibo
子目录多或者文件多的时候程序就会执行时间较长的。 |
|
| 返回顶楼 | |
|
时间:2008-05-05
用stepCounter插件就可以了 它会生成一个报表 很清晰明了
|
|
| 返回顶楼 | |
|
时间:2008-05-05
显然是shell最快了
|
|
| 返回顶楼 | |
|
时间:2008-05-06
robbin 写道 你这样也忒麻烦了,我一行shell命令就搞定了:
find . -type f -iname "*.java" -exec cat {} \; | wc -l
像你那么兴师动众写一大陀Java代码真是画蛇添足。 BTW: wc *.java是不行滴,要加 -l 参数,还不能遍历子目录 楼主写这个可以提高编程水平,又不是提高工作效率~ |
|
| 返回顶楼 | |
|
时间:2008-05-06
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class CodeCounter
{
static long normalLines = 0;
static long commentLines = 0;
static long blankLines = 0;
public static void main(String[] args)
{
File f = new File("D:\\java");
File[] codeFiles = f.listFiles();
for (File child : codeFiles)
{
if (child.getName().matches(".*\\.java$"))
{
parse(child);
}
}
System.out.println("正常代码:" + normalLines);
System.out.println("注释代码:" + commentLines);
System.out.println("空白行:" + blankLines);
}
private static void parse(File f)
{
BufferedReader br = null;
boolean comment = false;
try
{
br = new BufferedReader(new FileReader(f));
String line = "";
while ((line = br.readLine()) != null)
{
line = line.trim();
if (line.matches("^[\\s&&[^\\n]]*$"))
{
blankLines++;
} else if (line.startsWith("/*") && !line.endsWith("*/"))
{
commentLines++;
comment = true;
} else if (line.startsWith("/*") && line.endsWith("*/"))
{
commentLines++;
} else if (true == comment)
{
commentLines++;
if (line.endsWith("*/"))
{
comment = false;
}
} else if (line.startsWith("//"))
{
commentLines++;
} else
{
normalLines++;
}
}
} catch (FileNotFoundException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
} finally
{
if (br != null)
{
try
{
br.close();
br = null;
} catch (IOException e)
{
e.printStackTrace();
}
}
}
}
}
|
|
| 返回顶楼 | |
|
时间:2008-05-06
re: wang8118
你的程序考虑的比较全面,学习ing... |
|
| 返回顶楼 | |



