E企盈营销工具技术服务商 热线:4006-838-530

统计代码量小程序

E企盈直播平台营销卖货系统

统计代码量小程序  package com.handson.day8; import java.io.BufferedReader;import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStreamReader; public class CountLine {        //代码总行数        public  static int counts=0;//代码空格总行数        publicstatic int spaces=0;         publicstatic void main(String[] args) throws IOException {                  //创建对象                       CountLinec=new CountLine();                  //创建一个File对象,将工程的的完整路径放入其中,注意:一定要到src目录下                  Filefile=new File(“F:\StudySoft\MyEclipse\MyEclipse  作品\AttendanceManageSystem\src”);                                    //调用方法,输出各个包下的文件的代码行数                  c.readFile(file);//输出代码的总行数和代码中空格的总行数                       System.out.println(“总数”+counts+”行,其中空格有”+spaces+”行”);        }                //将读取包内个文件封装成方法        publicvoid readFile(File file) throws IOException{                  //如果是目录                                    //判断是否是目录                  if(file.isDirectory()){                           //获取目录里所有文件的集合                           File[]files=file.listFiles();                           //遍历文件集合                           for(inti=0;ifiles.length;i++){                                    //再次调用readFile()f方法,读取文件                                    readFile(files[i]);                           }                  }else{                           //获取字符缓冲流,并将文件放入                           BufferedReaderbr=new BufferedReader(new InputStreamReader(new FileInputStream(file)));                           //定义一个字符串对象,用于存储读取的数据String ss=””;//定义一个局部变量,记录当前文件的代码总行数                           intcount=0;//定义局部变量,记录当前文件的的空格数                           intcountSpace=0;                           //判断文件是否读取结束                           while((ss=br.readLine())!=null){                                    //判断次行是否为空行                                    if(“”.equalsIgnoreCase(ss.trim())){                                              countSpace++;                                              spaces++;                                    }                                    count++;                                    counts++;                           }                  //输出当前文件的代码量                  System.out.println(file.getCanonicalPath()+”:”+file.getName()+”有”+count+”行代码,其中空格”+countSpace+”行”);                                             }        } }

赞(0) 打赏
未经允许不得转载:E企盈小程序开发-热线:4006-838-530 » 统计代码量小程序
分享到: 更多 (0)
E企盈小程序直播营销卖货系统
E企盈直播平台营销卖货系统

评论 抢沙发

E企盈小程序开发

联系我们联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏