隨筆:20 文章:1 評(píng)論:8 引用:0
╰⊙д⊙╯。oо○
面朝大海·春暖花開
BlogJava
首頁(yè)
發(fā)新隨筆
發(fā)新文章
聯(lián)系
聚合
管理
計(jì)算指定路徑下所有java文件的代碼行數(shù)
import
java.io.File;
import
java.io.FileNotFoundException;
import
java.io.BufferedReader;
import
java.io.FileReader;
import
java.io.IOException;
public
class
CountCodeLines
{
private
static
int
codeLines
=
0
;
private
static
int
whiteLines
=
0
;
private
static
int
commentLines
=
0
;
private
static
int
tatolLines
=
0
;
private
static
boolean
bComment
=
false
;
public
static
void
main(String[] args)
{
StringBuffer pathName
=
new
StringBuffer(
"
c:/test/
"
);
ComputeDirectoryAndFiles(pathName,
0
);
codeLines
=
tatolLines
-
commentLines
-
whiteLines;
System.out.println(
"
Code Lines:
"
+
codeLines
+
"
\n
"
+
"
White Lines:
"
+
whiteLines
+
"
\n
"
+
"
Comment Lines:
"
+
commentLines);
}
public
static
void
ComputeDirectoryAndFiles(StringBuffer pathName,
int
level)
{
File directory
=
new
File(pathName.toString());
File[] files
=
directory.listFiles();
String prefix
=
""
;
for
(
int
i
=
0
; i
<
files.length; i
++
)
{
prefix
+=
"
**
"
;
}
//
當(dāng)且僅當(dāng)此抽象路徑名表示的文件存在且是一個(gè)目錄時(shí),返回true;否則返回 false
if
(directory.isDirectory())
{
for
(
int
i
=
0
; i
<
files.length; i
++
)
{
if
(files[i].isFile()
&&
files[i].getName().matches(
"
^[a-zA-Z[^0-9]]\\w*.java$
"
))
{
computeLines(files[i]);
}
if
(files[i].isDirectory())
{
pathName.append(
"
/
"
+
files[i].getName());
level
++
;
ComputeDirectoryAndFiles(pathName, level);
int
start
=
pathName.toString().length()
-
files[i].getName().length()
-
1
;
int
end
=
pathName.toString().length();
pathName.delete(start, end);
level
--
;
}
}
}
}
public
static
void
computeLines(File file)
{
BufferedReader bf
=
null
;
try
{
bf
=
new
BufferedReader(
new
FileReader(file));
String lineStr
=
""
;
while
((lineStr
=
bf.readLine())
!=
null
)
{
//
總行數(shù)
tatolLines
++
;
//
計(jì)算空行
whiteLines(lineStr);
//
統(tǒng)計(jì)代碼行數(shù)
commendLines(lineStr);
//
計(jì)算代碼的行數(shù)
//
codeLines(lineStr);
}
}
catch
(FileNotFoundException e)
{
System.out.println(
"
文件沒有找到
"
);
}
catch
(IOException ee)
{
System.out.println(
"
輸入輸出異常
"
);
}
finally
{
if
(bf
!=
null
)
{
try
{
bf.close();
bf
=
null
;
}
catch
(Exception e)
{
System.out.println(
"
關(guān)閉BufferReader時(shí)出錯(cuò)
"
);
}
}
}
}
//
判斷是否為空行
public
static
void
whiteLines(String lineStr)
{
if
(lineStr.matches(
"
^[\\s&&[^\\n]]*$
"
))
{
whiteLines
++
;
}
}
//
判斷是否是一個(gè)注釋行
public
static
void
commendLines(String lineStr)
{
//
這里是單行注釋的如 /*
.. */或/**
. */
if
(lineStr.matches(
"
\\s*/\\*{1,}.*(\\*/).*
"
))
{
commentLines
++
;
}
//
這里是多行注釋的
//
這里的是當(dāng)開始為/**或/*但是沒有 */ 關(guān)閉時(shí)
else
if
(lineStr.matches(
"
\\s*/\\*{1,}.*[^\\*/].*
"
))
{
commentLines
++
;
bComment
=
true
;
}
else
if
(
true
==
bComment)
{
commentLines
++
;
if
(lineStr.matches(
"
\\s*[\\*/]+\\s*
"
))
{
bComment
=
false
;
}
}
else
if
(lineStr.matches(
"
^[\\s]*//.*
"
))
{
commentLines
++
;
}
}
}
發(fā)表于 2008-04-29 22:21
dreamingnest
閱讀(860)
評(píng)論(0)
編輯
收藏
新用戶注冊(cè)
刷新評(píng)論列表
只有注冊(cè)用戶
登錄
后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
CALENDER
<
2008年4月
>
日
一
二
三
四
五
六
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
10
常用鏈接
我的隨筆
我的文章
我的評(píng)論
我的參與
最新評(píng)論
留言簿
(1)
給我留言
查看公開留言
查看私人留言
隨筆分類
(13)
應(yīng)用程序(4)
(rss)
數(shù)據(jù)結(jié)構(gòu)(java)
(rss)
算法程序總結(jié)(2)
(rss)
鏈表和棧(結(jié))(7)
(rss)
隨筆檔案
(21)
2008年10月 (1)
2008年5月 (7)
2008年4月 (13)
外面的世界
懶散狂徒的專欄(天行健,君子以自強(qiáng)不息 地勢(shì)坤,君子以厚德載物)
(rss)
這里的朋友
保爾任(思想比知識(shí)更重要 成長(zhǎng)比成功更重要)
搜索
最新評(píng)論
1.?re: BFS和DFS兩種方法獲取指定目錄下的所有目錄和文件
學(xué)習(xí)了
--fejay
2.?re: 關(guān)于螞蟻問題(Ants)
實(shí)際過程可以這么進(jìn)行抽象模擬:
序列中的元素帶有方向,進(jìn)行負(fù)值部分移動(dòng)到負(fù)值區(qū)域,正值部分移動(dòng)到正值區(qū)域時(shí)就不再發(fā)生碰撞,此時(shí)絕對(duì)值最小的值決定剩余爬行時(shí)間
--zdh
3.?re: 關(guān)于螞蟻問題(Ants)
這個(gè)問題看到實(shí)質(zhì)就很簡(jiǎn)單,所有的螞蟻都是相同的螞蟻,因此可以看成所有的螞蟻都可以穿過對(duì)面爬過來(lái)的螞蟻就ok啦,最長(zhǎng)時(shí)間就是兩端的螞蟻向另一端爬出去,最短的就是兩端的四個(gè)螞蟻向所在端爬出:)
--zdh
4.?re: 關(guān)于螞蟻問題(Ants)
評(píng)論內(nèi)容較長(zhǎng),點(diǎn)擊標(biāo)題查看
--blues
5.?re: 關(guān)于螞蟻問題(Ants)
評(píng)論內(nèi)容較長(zhǎng),點(diǎn)擊標(biāo)題查看
--dreamingnest
閱讀排行榜
1.?關(guān)于螞蟻問題(Ants)(2242)
2.?通過排序總結(jié)java泛型數(shù)組列表(1649)
3.?堆棧解(非遞歸)決迷宮問題(1414)
4.?ACM中使用JAVA的介紹(1048)
5.?~·掃雷小游戲·~(1035)
評(píng)論排行榜
1.?關(guān)于螞蟻問題(Ants)(7)
2.?BFS和DFS兩種方法獲取指定目錄下的所有目錄和文件(1)
3.?一著名軟件公司的java筆試算法題的答案 (0)
4.?堆棧解(非遞歸)決迷宮問題(0)
5.?堆排序代碼(0)
Powered By:
博客園
模板提供
:
滬江博客
主站蜘蛛池模板:
亚洲中文字幕无码中文
|
性做久久久久久久免费看
|
亚洲AV无码AV男人的天堂不卡
|
国产日韩亚洲大尺度高清
|
国产在线播放免费
|
免费国产作爱视频网站
|
日本免费污片中国特一级
|
男人免费视频一区二区在线观看
|
亚洲乱码一二三四区乱码
|
亚洲好看的理论片电影
|
亚洲综合无码精品一区二区三区
|
毛片免费视频播放
|
亚洲视频免费一区
|
男人天堂免费视频
|
h片在线播放免费高清
|
美美女高清毛片视频黄的一免费
|
亚洲最大的成人网
|
亚洲色欲色欲www
|
亚洲欧洲日本天天堂在线观看
|
亚洲av丰满熟妇在线播放
|
亚洲一区二区三区AV无码
|
亚洲国产精品狼友中文久久久
|
四色在线精品免费观看
|
成人免费在线观看网站
|
亚洲欧洲免费无码
|
67194熟妇在线永久免费观看
|
最近中文字幕免费完整
|
8x8×在线永久免费视频
|
亚洲成人免费在线
|
久久永久免费人妻精品下载
|
久久er国产精品免费观看2
|
99视频在线观看免费
|
a级午夜毛片免费一区二区
|
a毛片视频免费观看影院
|
免费国产在线视频
|
一级毛片免费观看不卡视频
|
久久九九兔免费精品6
|
国产h肉在线视频免费观看
|
免费可以看黄的视频s色
|
在线观看成人免费视频
|
国产成人无码区免费A∨视频网站
|