public class ReadFile {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
Long globalNum = 0L; // 总行数
List<Long> lineNums = new ArrayList<Long>();
List<String> exceptFileNames = new ArrayList<String>();
exceptFileNames.add( "project2" );//不统计目录
exceptFileNames.add( "test");//不统计目录
String path = "D:\\source\\project" ;//项目目录
File file = new File(path);
traversalFile(file, lineNums, exceptFileNames);
for (Long num : lineNums) {
globalNum = globalNum + num;
}
System. out.println(globalNum); // 310375
}
/**
* 得到目录的叶子java文件,并统计文件里有多少行,将行数放到list中
*
* @param file
* @throws IOException
*/
public static void traversalFile(File file, List<Long> lineNums,
List<String> exceptFileNames) throws IOException {
File[] childList = file.listFiles();
String fileName = null;
String extra = null;
for (File child : childList) {
fileName = child.getName();
if (child.isDirectory()) {
if (exceptFileNames != null
&& !exceptFileNames.contains(child.getName())) {
traversalFile(child, lineNums, exceptFileNames);
}
} else {
extra = fileName.contains( ".") ? fileName.substring(fileName
.lastIndexOf( ".")) : fileName;
if (extra.equals( ".java") || extra.equals(".jsp" )
|| extra.equals( ".js")) {
System. out.println(child.getName().substring(
child.getName().lastIndexOf( ".")));
lineNums.add( getLineNum(child));
}
}
}
}
/**
* 得到某个文件有多少行(非目录)
*
* @param file
* @return
* @throws IOException
*/
public static long getLineNum(File file) throws IOException {
long num = 0L;
FileInputStream f = new FileInputStream(file);
BufferedReader dr = new BufferedReader( new InputStreamReader(f));
String line = dr.readLine();
while (line != null) {
if (!line.trim().equals( "")) {
num++;
}
line = dr.readLine();
}
return num;
}
}
相关推荐
visual studio和eclipse如何统计代码行数
可以统计代码行数的插件,测试完全,保证正确,可以统计工程目录,单个文件,多个文件java代码中注释,代码行数
C#统计代码行数 VS2013编译 可以定义拓展名 包含文件和文件夹
用于统计项目的代码行数。在代码中修改路径即可。适用于多种文件格式。
Count Lines of code 统计代码行数
统计代码行数的idea插件,可以很好地将统计的结果分类显示,分成java行数,xml行数,properties行数
代码行数统计工具,所有项目通用,代码行数统计工具,所有项目通用
代码行数计算工具 win版 计算代码行数 使用方法看说明.txt 文档
通过该工具可以方便的统计出自己所写得代码行数,可以选择不同的文件类型来进行统计,exe文件
用于程序员统计代码行数的工具,使用方便快捷,很快就能给出统计结果,并且可以设置统计的方法和形式,可用于管理程序员的工作量
可以统计一个或多个文件夹内代码的行数 支持自定义文件扩展名 支持"{","}"识别 如 可设置将 { Response.End(); } 视作一行或三行.. 等
一个统计代码行数的小工具,绿色,支持多种代码格式:xml,vb,c,sql,h,sh,dfm,java,php,asp,txt,jsp,html,等等。
统计代码行数工具Kazoeciao.支持各种语言,需要到官网下载插件包. 官网:https://www.vector.co.jp/soft/winnt/prog/se251853.html 「かぞえチャオ!」は、ソフト開発における、規模見積りから生産性評価にまで使え...
一个用php做的统计php代码行数的程序
统计MATLAB代码行数的工具,封装成一个函数,在主函数中调用即可
用java实现统计代码行数,运行程序会统计编程的工作量以及有效代码的行数
用来统计开发代码的长度,非常的使用,什么程序都可以统计
代码行数统计工具,特别好用,可以统计代码的注释行数、空行数、代码有效行数。值得拥有。 代码行数统计工具,特别好用,可以统计代码的注释行数、空行数、代码有效行数。值得拥有。
统计代码行数