java实现统计代码行数
2013-05-03 21:42
639 查看
贴个自己的代码可以统计指定目录或文件的行数,不统计空行,但是统计注释。
import java.io.*; import java.util.*; public class LineCounts{ public LineCounts(){ } public int getAllLineCounts(File dir){ if(!dir.isDirectory()){ return getLineCounts(dir); } File[] fileLists = dir.listFiles(); int count = 0; for(int i = 0 ;i < fileLists.length; i ++){ File file = fileLists[i]; if(file.isDirectory()){ System.out.println("Directory: " + file.getName()); int currentCount = getAllLineCounts(file); count = count + currentCount; System.out.println("目录"+ file.getName() + "共" + currentCount + "行\n"); }else{ System.out.print("File name: " + file.getName()); int currentCount = getLineCounts(file); count = count + currentCount; System.out.println(" " + currentCount + "行"); } } return count; } public int getLineCounts(File file){ int count = 0; try{ BufferedReader in = new BufferedReader(new FileReader(file)); String line; while((line = in.readLine()) != null){ if(!line.equals("") ){ count ++; } } }catch(FileNotFoundException e){ e.printStackTrace(); }catch(IOException e){ e.printStackTrace(); } return count; } public static void main(String[] args){ File dir = new File(args[0]); LineCounts lc = new LineCounts(); int count = lc.getAllLineCounts(dir); System.out.println("共 " + count + " 行"); } }
使用截图:
相关文章推荐
- 代码行数统计java实现
- 代码行数统计的Java和Python实现
- 统计你写的java代码行数
- [JAVA实用应用] 项目代码行数统计器,帮助你统计项目一共有多少行代码
- Java代码行数的统计
- 统计文件夹下java代码行数
- 项目代码行数统计--java类统计
- C#第一次作业,C#或者java代码总行数、代码行数、代码空格行数、注释行数的统计
- 代码行数统计(python实现)
- python实现代码行数统计示例分享
- 利用正则表达式统计某个某个文件夹下所有java文件的 空格行数、注释行数、和代码行数
- 代码注释率统计的Python及Java实现
- 通过java实现代码规模统计并把结果导出至execl中
- 统计某java文件中的代码行数、某个字符(char)、某字符串(String)出现的次数
- 实现统计java程序代码的小工具
- 快速统计java代码行数
- JAVA 第一次作业 统计代码文件行数【空行+注释行+代码行】
- Java统计脚本代码行数
- java统计代码行数
- 统计java代码行数