网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

统计java工程代码行数 怎样统计程序代码行数

如何计算一个.java文件的代码行数

方法一:

成都创新互联公司坚持“要么做到,要么别承诺”的工作理念,服务领域包括:网站建设、成都网站制作、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的井研网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

如果想要通过java代码的方式来计算.java文件的行数,可以通过IO来读取,

BufferedReader的方法readLine()来按行读取,每读取一行,行数+1

方法二:

如果要查看.java文件的代码行数,

可以使用现成的IDE工具,比如ECLIPSE...

每一行的行号都有表示出来

eclipse怎么统计代码行数

Eclipse可以方便的统计工程或文件的代码行数。方法如下:

1.首先选中你要统计的工程,在菜单栏点击Search,然后点击File...

2.选中右侧正则表达式(Regular expression),并在搜索文本框输入\n

3.在文件名中输入*或*.java

4.在范围里选中Enclosing projects

5.在Search窗口就会显示出项目或文件的代码行数

求问怎么统计JAVA代码行数?有什么工具?

源代码行数统计器 1.5

本软件用于统计软件工程源代码行数,

可对指定的子目录下或整个目录树中所有指定类型的源代码文件进行行数统计。

如何统计某目录下的java文件代码行数

可以自己写一个小程序,遍历每个文件;

如果是*.java就记录该文件的行数,依次累加。

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工程代码行数 怎样统计程序代码行数
网站路径:http://bjjierui.cn/article/hgdigo.html

其他资讯