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

熱點內容
怎麼查伺服器假死原因日誌在哪看 瀏覽:277
掃描pdf文件 瀏覽:926
解壓密碼百度雲在線解壓 瀏覽:767
傳播學演算法推薦 瀏覽:749
我的世界網路游戲如何查找伺服器 瀏覽:257
安卓和蘋果通訊錄怎麼互傳 瀏覽:203
怎麼打開隱私與應用加密的菜單 瀏覽:416
我的世界伺服器小游戲的地址大全 瀏覽:578
在網路安全中加密安全機制提供了數據的 瀏覽:249
南京前端程序員私活怎麼收費 瀏覽:981
拓撲pdf 瀏覽:440
如何在工行app查我的訂單 瀏覽:214
車壓縮機改電動 瀏覽:83
如何尋找音樂app 瀏覽:831
一加加密的照片 瀏覽:200
阿里雲虛擬主機php 瀏覽:639
不卡點的解壓視頻 瀏覽:391
hex文件下載單片機 瀏覽:873
實現編譯器的自展技術 瀏覽:655
app開發者怎麼突破 瀏覽:418