读取所有的行,包括空格行
public class Demo2 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new FileReader(new File("MySQL.txt")));
int count = 0;
while(br.readLine()!=null){
count++;
}
System.out.println(count);
}
}
只读取有效行 ,空格行不算数
public class Demo2 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new FileReader(new File("MySQL.txt")));
String len = null;
int count = 0;
while((len= br.readLine())!=null){
//String 的方法 trim的效果是把一个字符串的左右两边的空格都去掉,剩下中间的字符串
//下面的这一步 的作用就是过滤掉空格行
if(!len.trim().equals("")){
count++;
}
}
System.out.println(count);
}
}