// 在此编写你的代码
String file;
try {
file = new BufferedReader(new InputStreamReader(System.in)).readLine();
} catch (IOException e) {
e.printStackTrace();
return;
}
BufferedReader r = null;
FileInputStream in = null;
try {
in = new FileInputStream(file);
r = new BufferedReader(new InputStreamReader(in));
String line;
while ((line = r.readLine()) != null) System.out.println(line);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if(r != null) {
try {
r.close();
} catch (IOException e) {
e.printStackTrace();
}
}
//TODO 需要关??????
//before in.close() try to read and Exception Stream Closed
//System.out.println(">>>>>>>" + in.read());
//So why teach us to close duplicate?
if(in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
So why teach us to close duplicate?
正在讨论
评论
- 受欢迎
- 新
- 旧
你必须先登录才能发表评论
此页面还没有任何评论