//关于这个使用带缓冲功能的字节流复制文件的小问题,有点错误想请教一下高手修改并提示一下错误的位置及原因,谢谢!
package jichu;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
//使用带缓冲功能的字节流复制文件
public class CopyFile {
public static void main(String[] args) {
BufferedReader bfr =null;
BufferedWriter bfw =null;
try{
bfr = new BufferedReader(new InputStreamReader(new FileInputStream(new File("c:\\2.txt")))) ;
bfw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("D:\\3.txt"))) ;
byte[] bytes = new byte[1024];
String length = null;
while((length=bfr.readLine(bytes))!=null){
bfw.write(bytes,0,length);
bfw.flush();
}
}catch(IOException e){
e.printStackTrace();
throw new RuntimeException();
}finally{
if(bfr!=null)
bfr.close();
}finally{
if (bfw!=null) {
bfw.close();
}
}
}
}
|