public class Exercise1 {
public static void main(String[] args) throws IOException {
LineNumberReader lnr = new LineNumberReader(new FileReader("day19-笔记.txt"));
List<String> list = new ArrayList<String>();
String b;
while ((b = lnr.readLine()) != null)
list.add(lnr.getLineNumber() + ":" + b);
lnr.close();
BufferedWriter bw = new BufferedWriter(new FileWriter("exercise1day19.txt"));
for(String s : list) {
bw.write(s);
bw.newLine();
}
bw.close();
}
}
红色部分是关闭流
那我能不能一起关闭呢
以下:
BufferedWriter bw = new BufferedWriter(new FileWriter("exercise1day19.txt"));
for(String s : list) {
bw.write(s);
bw.newLine();
}
lnr.close();
bw.close();
}
那么怎么确定什么时候该关流呢?
|