導航:首頁 > 編程語言 > 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統計代碼行數相關的資料

熱點內容
程序員復盤app 瀏覽:159
pdf確定 瀏覽:513
php連接mysql埠號 瀏覽:976
id3演算法在進行某個節點劃分時 瀏覽:383
麥塊伺服器如何登錄正版 瀏覽:663
中國民俗學pdf 瀏覽:362
程序員如何做人力資源 瀏覽:655
p單片機數字電壓表項目設計報告 瀏覽:425
做一個單片機系統要經過哪些步驟 瀏覽:129
阿里雲php版本升級 瀏覽:331
pdf轉換word綠色 瀏覽:335
使用代理伺服器地址和埠怎麼填 瀏覽:364
php獲取當天的日期時間戳 瀏覽:149
aix命令補全 瀏覽:65
文件加密後無法打開怎麼解決 瀏覽:150
如何暴力下載app視頻 瀏覽:604
802d編程書籍 瀏覽:413
ug一步式展開命令詳解 瀏覽:301
嵌入式軟體pdf 瀏覽:804
抓老鼠的程序員 瀏覽:117