欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

如何統(tǒng)計java代碼行數(shù) 如何統(tǒng)計java代碼行數(shù)的個數(shù)

Java 有什么好的代碼行數(shù),注釋行數(shù)統(tǒng)計工具

package com.syl.demo.test;

作為一家“創(chuàng)意+整合+營銷”的成都網(wǎng)站建設(shè)機(jī)構(gòu),我們在業(yè)內(nèi)良好的客戶口碑。成都創(chuàng)新互聯(lián)公司提供從前期的網(wǎng)站品牌分析策劃、網(wǎng)站設(shè)計、網(wǎng)站建設(shè)、網(wǎng)站制作、創(chuàng)意表現(xiàn)、網(wǎng)頁制作、系統(tǒng)開發(fā)以及后續(xù)網(wǎng)站營銷運(yùn)營等一系列服務(wù),幫助企業(yè)打造創(chuàng)新的互聯(lián)網(wǎng)品牌經(jīng)營模式與有效的網(wǎng)絡(luò)營銷方法,創(chuàng)造更大的價值。

import java.io.*;

/**

* java代碼行數(shù)統(tǒng)計工具類

* Created by 孫義朗 on 2017/11/17 0017.

*/

public class CountCodeLineUtil {

private static int normalLines = 0; //有效程序行數(shù)

private static int whiteLines = 0; //空白行數(shù)

private static int commentLines = 0; //注釋行數(shù)

public static void countCodeLine(File file) {

System.out.println("代碼行數(shù)統(tǒng)計:" + 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文件統(tǒng)計:" +

"總有效代碼行數(shù): " + normalLines +

" ,總空白行數(shù):" + whiteLines +

" ,總注釋行數(shù):" + commentLines +

" ,總行數(shù):" + (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("*/")) {

// 為多行注釋中的一行(不是開頭和結(jié)尾)

commentLines++;

temp_commentLines++;

} else if (comment == true line.endsWith("*/")) {

// 為多行注釋的結(jié)束行

commentLines++;

temp_commentLines++;

comment = false;

} else if (line.startsWith("http://")) {

// 單行注釋行

commentLines++;

temp_commentLines++;

} else {

// 正常代碼行

normalLines++;

temp_normalLines++;

}

}

System.out.println(file.getName() +

" ,有效行數(shù)" + temp_normalLines +

" ,空白行數(shù)" + temp_whiteLines +

" ,注釋行數(shù)" + temp_commentLines +

" ,總行數(shù)" + (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編寫統(tǒng)計文件中的字符數(shù)、單詞數(shù)和行數(shù)?

public class Test {\x0d\x0a\x0d\x0a public static void main(String[] args) throws Exception{\x0d\x0a Scanner input=new Scanner(System.in);\x0d\x0a System.out.println("請輸入路徑");\x0d\x0a String path=input.next();\x0d\x0a int charNum= 0 ;\x0d\x0a int wordsNum= 0;\x0d\x0a int lineNum = 0;\x0d\x0a InputStreamReader isr = new InputStreamReader(new FileInputStream(path)); \x0d\x0a BufferedReader br = new BufferedReader(isr);\x0d\x0a while( br.read()!= -1){\x0d\x0a String s = br.readLine();\x0d\x0a charNum+=s.length();\x0d\x0a wordsNum +=s.split(" ").length;\x0d\x0a lineNum ++; \x0d\x0a }\x0d\x0a isr.close();//關(guān)閉\x0d\x0a System.out.println("字符數(shù):"+charNum+"\t單詞數(shù):"+wordsNum+"行 數(shù):"+lineNum); \x0d\x0a\x0d\x0a }\x0d\x0a}

如何統(tǒng)計某目錄下的java文件代碼行數(shù)

可以自己寫一個小程序,遍歷每個文件;

如果是*.java就記錄該文件的行數(shù),依次累加。

網(wǎng)頁題目:如何統(tǒng)計java代碼行數(shù) 如何統(tǒng)計java代碼行數(shù)的個數(shù)
分享網(wǎng)址:http://chinadenli.net/article30/dodepso.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機(jī)、搜索引擎優(yōu)化、靜態(tài)網(wǎng)站網(wǎng)站設(shè)計、用戶體驗、App開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁設(shè)計