不会,开几个流,结束的时候就要关闭几个流。
不会自动关闭的,但是可使用这种语法优化,使之自动关闭
public static void main(String[] args) {
// TRY 代码块执行完成之后自动关闭TRY()里面的实现Closeable接口的变量
try (FileOutputStream fos = new FileOutputStream("rrr.txt");
ObjectOutputStream oos = new ObjectOutputStream(fos)) {
oos.writeObject("TEST");
oos.writeObject("TEST2");
} catch (IOException ignore) {
// Handle Exception In Here ...
}
}
会关闭!!!