package class_1;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class LineCount {
public void read(String filePath){
try{
BufferedReader br = new BufferedReader(new FileReader(filePath));
String line = null;
int count = 0;
while((line = br.readLine())!=null){
count ++;
}
System.out.println("行数是:" + count);
}catch(FileNotFoundException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}
}
public static void main(String[] args) {
LineCount lc = new LineCount();
lc.read("D://Test.java");
}
}
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class LineCount {
public void read(String filePath){
try{
BufferedReader br = new BufferedReader(new FileReader(filePath));
String line = null;
int count = 0;
while((line = br.readLine())!=null){
count ++;
}
System.out.println("行数是:" + count);
}catch(FileNotFoundException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}
}
public static void main(String[] args) {
LineCount lc = new LineCount();
lc.read("D://Test.java");
}
}