刚才太乱了再发一次,大神快来解决啊
FileOutputStream out = null;
OutputStreamWriter writer = null;
try {
out = new FileOutputStream("OutputStream.txt");
writer = new OutputStreamWriter(out);//字节流转换为字符流
String s = "hello world 字节流";//字符
writer.write(s);
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
if(writer!=null)writer.close();
if(out!=null)out.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
在这个程序的最后我分别作了字符流和字节流的关闭操writer.close();out.close();
但看完缓冲区的视频后,老师指明 BufferWriter.close()就已经关闭了字符流,所以不需要再执行Writer.close()
所以不禁想起了上面那个例子是否只关闭字符流就可以了?
坐等答案哦,欢迎在线讨论
|
|