FileInputStream in = new FileInputStream(srcFile);
InputStreamReader isr = new InputStreamReader(in);
FileOutputStream out = new FileOutputStream(desFile);
OutputStreamWriter osw = new OutputStreamWriter(out);
最后关闭的时候只要isr.close(); osw.close();这两个都关闭了就行吗?in和out不需要关闭吗?
但是我刚才也试了下,
FileInputStream inf=new FileInputStream("Demo/dddd.txt");
InputStreamReader isr=new InputStreamReader(inf,"UTF-8");
FileOutputStream outf=new FileOutputStream("Demo/dos.dat");
OutputStreamWriter osw=new OutputStreamWriter(outf);
isr.close();
osw.close();
byte[] s=new byte[8*1024];
while ((c=inf.read(s, 0, s.length))!=-1) {
outf.write(s, 0, c);
}
这样去读取的时候,会报read error,跟提前关掉inf和outf去读取时候一样
我本人也不太清楚,但是我问了工作群里面,说的是都需要关闭
in和out是低级流,外面套着isr和osw高级流,关闭的时候只需要关闭最外层的就可以了。
都需要关闭