下面是我的代码,从输出文件中获得特定行。它给了我上面的错误。当我刚接触这个时,可以请一些帮助我。
private final static String ThirdDeviceName=iPhone();
public static String iPhone() throws IOException {
BufferedReader br = new BufferedReader(new FileReader("output.txt"));
String str;
int start = 0;
int end = 0;
int count = 0;
while((str = br.readLine())!= null)
{
StringTokenizer st = new StringTokenizer(str," ");
count++;
System.out.println(st.nextToken());
}
br.close();
return str;
}
最佳答案
简短的答案:您的方法将引发IOException,但您不会在任何地方捕获它。因此未处理。如果常量抛出异常,则不能使用该方法。
使用try-catch块而不是在方法中重新抛出异常,或者使用在方法内部设置的非最终属性,您可以在其中执行try-catch块。
关于java - 使用方法从文本文件获取输出时,未处理的异常类型IOException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38586139/