1. 程式人生 > >java讀取txt檔案,獲取行數

java讀取txt檔案,獲取行數

public void readFile() throws FileNotFoundException {
int count=1;
File file = new File("..\\ReadFile\\test.txt");
FileInputStream fis = new FileInputStream(file);
Scanner scanner = new Scanner(fis);
while(scanner.hasNextLine()){
scanner.nextLine();
count++;
}
System.out.println(count);

}