国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

java源碼之代碼統(tǒng)計(jì)

2019-11-14 10:08:40
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

源碼

import java.io.* ;import java.nio.* ;import java.util.* ;import java.util.regex.* ;import java.nio.channels.FileChannel ;import java.nio.charset.* ;public class CodeStatistics{ //統(tǒng)計(jì)代碼行 static int codeLine = 0 ; //注釋行代碼統(tǒng)計(jì) static int annoLine = 0 ; //{}統(tǒng)計(jì) static int backetLine = 0 ; static int searchDirectory( String str ) throws NotFoundFileException { File f = new File(str) ; //判斷是路徑是否是目錄或文件。 if (f.isDirectory()) { return 1 ; }else if (f.isAbsolute()) { return 0 ; } else { throw new NotFoundFileException("沒有找到該文件,該目錄無(wú)效") ; } } static void coderEn( String filePath , int key ) { if ( key == 0 ) { File fileName = new File(filePath) ; if(fileName.getName().matches(".*//.java$")) { Count(filePath) ; } } if ( key == 1 ) { File f1 = new File(filePath) ; File[] downFile = f1.listFiles() ; for (File tmp : downFile) { String f1Name = tmp.getPath() ; int size = searchDirectory(f1Name) ; coderEn( f1Name , size ) ; } } } static void Count( String fileName) { try (BufferedReader br = new BufferedReader( new FileReader(fileName))) { String MuStr = null ; while ((MuStr = br.readLine()) != null) { MuStr = MuStr.trim() ; if (MuStr.startsWith("http://") || MuStr.startsWith("*") || MuStr.startsWith("*/") || MuStr.startsWith("/*") || MuStr.equals("")) { annoLine ++ ; } else if (MuStr.startsWith("{") || MuStr.startsWith("}")) { backetLine ++ ; } else { codeLine ++ ; } } } catch (Exception e) { e.PRintStackTrace() ; } } public static void main ( String[] args ) { try(BufferedReader br = new BufferedReader( new InputStreamReader(System.in))) { String IOStr = null ; String filePath = null ; while ((IOStr = br.readLine()) != null ) { filePath = IOStr.replace( '//' , '/') ; coderEn( filePath , searchDirectory( filePath )) ; System.out.println("總行數(shù)為:" + ( codeLine + annoLine + backetLine )) ; System.out.println("總代碼行數(shù)統(tǒng)計(jì):" + codeLine ) ; System.out.println("注釋行代碼統(tǒng)計(jì):" + annoLine ) ; System.out.println("{}統(tǒng)計(jì):" + backetLine ) ; } } catch ( Exception e ) { e.printStackTrace() ; } }}

自定義異常類

public class NotFoundFileException extends RuntimeException{ public NotFoundFileException() { super() ; } public NotFoundFileException(String message) { super(message) ; }}
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 阳城县| 枣庄市| 郓城县| 扶余县| 班玛县| 西昌市| 勃利县| 琼海市| 嘉善县| 历史| 扎鲁特旗| 石渠县| 安陆市| 西林县| 贵州省| 曲阜市| 惠水县| 哈尔滨市| 环江| 广州市| 漠河县| 广河县| 嘉祥县| 博白县| 克东县| 新源县| 聂荣县| 保康县| 蒙山县| 南岸区| 彭水| 海兴县| 克东县| 营口市| 常州市| 白城市| 兴义市| 二连浩特市| 茶陵县| 陈巴尔虎旗| 东山县|