之后添加一个返回值
你好,我在try/catch块中返回我的linkedList的逻辑有问题。我现在有:
public static LinkedList<String> makeList(String textName) {
try {
BufferedReader in = new BufferedReader(new InputStreamReader(
new FileInputStream(textName), "UTF8"));
LinkedList<String> ll = new LinkedList<String>();
String line;
while ((line = in.readLine()) != null) {
ll.add(line);
}
return ll;
in.close();
} catch (UnsupportedEncodingException e) {
System.out.println(e.getMessage());
} catch (IOException e) {
System.out.println(e.getMessage());
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
显然,return语句只在try块中是错误的,但是当我在try和catch之外也有"return null"时,我仍然会得到一个错误。
您的in.close();
无法联系到,因为您正在返回之前。是的,您还应该在try catch块
将您的in.close()移到finally块