import java.io.*;public class Check {
public static void main (String[] args) throws IOException{
check("D:/MyEclipse/java/src/my/Check.java");//这里的字符串是你要统计的文件的路径,你自己填圆带写
} public static void check (String s) throws IOException{
int all = 0, empty = 0, describe = -1, i = 0;
String str = null;
File f = new File(s);
BufferedReader br = new BufferedReader (new FileReader(f));
str = br.readLine();
while(str != null){
all++;
if(str.trim().equals("")) empty++;
if(str.contains("//")) describe++;
if(str.contains("/*")){
while(!str.contains("*/")){
i++;
all++;
describe++;
str = br.readLine();
}
}
str = br.readLine();
}
System.out.println("文件物理总行数为:" + all);//;;klj
System.out.println("文件中空行数为:" + empty);//hkk
System.out.println("文件注释行数为:" + describe);
System.out.println("文件非注释行数为:" + (all - i));
/*asdfdsff
* sdasadfsf//fg
* asdfsdf//dsfg
* asdf
*/
}
}以上是代码,我在我的橘陵芦机子上实现了,希望能帮到你!我也是JAVA菜鸟,希望有高手能更好地解答汪族