怎样同时统计文件里的字符数和行数,为什么红色部分代码不能统计统计
import *;public class Example8 {
public static void main(String[]args){
int b = 0;
int charNum = 0;
int rowNum = 0;
String s;
try {
BufferedReader br = new BufferedReader(new FileReader("./Example8.java"));
while((b=br.read())!= -1) {
charNum++;
while((b=br.read())=='\n') {
rowNum++;
}
}
br.close();
System.out.println("Example8.length:" + charNum);
System.out.println("rowNumber:" + rowNum);
} catch(IOException e) {
e.toString();
System.exit(-1);
}
}
}
[ 本帖最后由 cl8972 于 2014-12-9 17:56 编辑 ]