导航:首页 > 编程语言 > java统计代码行数

java统计代码行数

发布时间:2023-05-02 01:37:23

1. 怎么用java编写统计文件中的字符数、单词数和行数

  1. 在C盘新建文件1.txt,输入任意字符,如下图:

2. eclipse怎么统计代码行数

步骤如下:

1、打开File Search对话框。
2、选中正则表达式,在搜索文本框输入\n 。
3、文件名称输入 *.java。
4、在范围里选中Enclosing projects。
经过上面方式,就可以统计出整个项目的代码行数。

3. 对日java项目开发来说,一个月平均能编写多少行代码,正常来说的标准是多少行代码

在日本早期的软件开发管理中,的确有按照代码行数来算开发成本的,但是,随着目标指向语言流行和软件开发管理的进步,这种方法已经很少见了。

而且,现在很流行开发工具自动化,很多代码都是自动生成的,很难计算一个月能写多少代码。
如果非要数字,平均一个月写3到10万行应该是不成问题的。

有一种叫做StepCounter的工具可以计算java代码行数,lz可以看一下。

4. Java 有什么好的代码行数,注释行数统计工具

package com.syl.demo.test;
import java.io.*;
/**
* java代码行数统计工具类
* Created by 孙义朗 on 2017/11/17 0017.
*/
public class CountCodeLineUtil {
private static int normalLines = 0; //有效程序行数
private static int whiteLines = 0; //空白行数
private static int commentLines = 0; //注释行数
public static void countCodeLine(File file) {
System.out.println("代码行数统计:" + file.getAbsolutePath());
if (file.exists()) {
try {
scanFile(file);
} catch (IOException e) {
e.printStackTrace();
}
} else {
System.out.println("文件不存在!");
System.exit(0);
}
System.out.println(file.getAbsolutePath() + " ,java文件统计:" +
"总有效代码行数: " + normalLines +
" ,总空白行数:" + whiteLines +
" ,总注释行数:" + commentLines +
" ,总行数:" + (normalLines + whiteLines + commentLines));
}
private static void scanFile(File file) throws IOException {
if (file.isDirectory()) {
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) {
scanFile(files[i]);
}
}
if (file.isFile()) {
if (file.getName().endsWith(".java")) {
count(file);
}
}
}
private static void count(File file) {
BufferedReader br = null;
// 判断此行是否为注释行
boolean comment = false;
int temp_whiteLines = 0;
int temp_commentLines = 0;
int temp_normalLines = 0;
try {
br = new BufferedReader(new FileReader(file));
String line = "";
while ((line = br.readLine()) != null) {
line = line.trim();
if (line.matches("^[//s&&[^//n]]*$")) {
// 空行
whiteLines++;
temp_whiteLines++;
} else if (line.startsWith("/*") && !line.endsWith("*/")) {
// 判断此行为"/*"开头的注释行
commentLines++;
comment = true;
} else if (comment == true && !line.endsWith("*/")) {
// 为多行注释中的一行(不是开头和结尾)
commentLines++;
temp_commentLines++;
} else if (comment == true && line.endsWith("*/")) {
// 为多行注释的结束行
commentLines++;
temp_commentLines++;
comment = false;
} else if (line.startsWith("//")) {
// 单行注释行
commentLines++;
temp_commentLines++;
} else {
// 正常代码行
normalLines++;
temp_normalLines++;
}
}
System.out.println(file.getName() +
" ,有效行数" + temp_normalLines +
" ,空白行数" + temp_whiteLines +
" ,注释行数" + temp_commentLines +
" ,总行数" + (temp_normalLines + temp_whiteLines + temp_commentLines));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
br = null;
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
//测试
public static void main(String[] args) {
File file = new File("F:\\myweb");
countCodeLine(file);
}
}

阅读全文

与java统计代码行数相关的资料

热点内容
手机上什么解压软件可以强制解压 浏览:781
win7有自带编译器吗 浏览:541
转接器连了没有文件夹 浏览:570
二手开利螺杆压缩机 浏览:309
有php基础学java要多久 浏览:300
程序员税后工资多少可以跳槽 浏览:172
个别网站无法解析服务器的dns地址 浏览:972
安卓手机如何打开rmb文件 浏览:215
新生儿app叫什么 浏览:65
斗鱼加密怎么弄 浏览:761
为什么会加密不可上网 浏览:531
步步高手机编译时间啥意思 浏览:396
程序员复盘app 浏览:162
pdf确定 浏览:538
php连接mysql端口号 浏览:1001
id3算法在进行某个节点划分时 浏览:408
麦块服务器如何登录正版 浏览:687
中国民俗学pdf 浏览:387
程序员如何做人力资源 浏览:658
p单片机数字电压表项目设计报告 浏览:450