zoukankan      html  css  js  c++  java
  • 用代码统计java代码行数

    public class Tongjidaima {
        private static int i;//代码总行数
        private static int j;//文件个数
        public static void main(String[] args) throws IOException {
            File file = new File("F:\eclipsework\Zhansen");//需要统计行数的文件夹路径
            traverseFiles(file);//调用递归方法查看.java文件,用于统计行数
            System.out.println("所写文件个数:"+j);
            System.out.println("所写代码总行数:"+i);
        }
        public static void traverseFiles(File file) throws IOException{    
            if(!file.exists()){//文件不存在
                return;
            }
            
            if(!file.isDirectory()){//判断是否为文件
                String filename = file.getName();
                if(filename.endsWith(".java")){//判断是否是.java文件
                    j++;
                    BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
                    String string =null;
                    while ((string = bufferedReader.readLine()) != null) {
                        i++;//读取行数
                    }
                }else
                   return;
            }
            
            File[] files =file.listFiles();//读取文件夹的子文件或子文件夹
            if (files == null || files.length == 0) {
                return;
            }
            
            for(File file2 : files){//如果是文件夹递归调用方法遍历文件
                traverseFiles(file2);
            }
        }    
    }
  • 相关阅读:
    多线程
    python 进程间通信
    python 生产者消费者模型
    多线程锁
    io多路复用(三)
    div 加滚动条的方法
    10矩形覆盖
    11.二进制中1的个数
    12数值的整数次方
    9 变态跳台阶
  • 原文地址:https://www.cnblogs.com/zs0322/p/11023644.html
Copyright © 2011-2022 走看看