从文本文件中逐行扫描,请问如何换行向下扫描?
文本如下:
zhang=1
san=2
扫描代码如下:
Scanner sc = new Scanner(new File("../test.txt") );
String rs1 = sc.findInLine("\\d+");
System.out.println(rs1 );
String rs2 = sc.findInLine("\\d+");
System.out.println(rs2 );
结果第一行正常,但是无法向下换行扫描
1
Exception in thread "main" java.lang.IllegalStateException: No match result available
at java.util.Scanner.match(Scanner.java:1293)
at zhc.Scan1.main(Scan1.java:24)
nextLine