在下面的代码中获取异常:
import java.io.*;
public static void main(String[] args) throws IOException{
FileReader objRead = new FileReader("/home/acer/Desktop/sulabh");
BufferedReader objB = new BufferedReader(objRead);
String input = null;
while((input=objB.readLine())!= null){
String temp = input.substring(0,2);
if(temp.contains("77")) {
System.out.println(input);
}
}
objB.close();
}
答案错误是:
777
777
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: begin 0, end 2, length 0 at java.base/java.lang.String.checkBoundsBeginEnd(String.java:3319) at java.base/java.lang.String.substring(String.java:1874) at Main.main(Main.java:10)