package k;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStreamReader;import java.io.OutputStreamWriter;public class IsrAndOswDemo { public static void main(String[] args) throws IOException { FileInputStream in=new FileInputStream("D:\\test\\日记3.txt"); InputStreamReader isr=new InputStreamReader(in,"gbk"); FileOutputStream out = new FileOutputStream("D:\\test\\日记1.txt"); OutputStreamWriter osw=new OutputStreamWriter(out,"gbk"); /*int c; while((c=isr.read())!=-1){ System.out.print((char)c); }*/ char[] buffer=new char[20*1024]; int c; //字节批量读取,返回的是读到的字节的个数 while((c=isr.read(buffer, 0, buffer.length))!=-1){ String s=new String(buffer,0,c); System.out.print(s); osw.write(buffer, 0, c); } osw.flush(); isr.close(); osw.close(); }}就像上方的代码,in和out没有close可以么? |