日期:2014-05-20  浏览次数:20640 次

帮忙看下这段读取字节流的代码哪里出问题了
本帖最后由 cnaaa8 于 2013-01-17 09:41:49 编辑

public static void copy3(){
BufferedInputStream frs=null;
BufferedOutputStream fws=null;
try {
frs=new BufferedInputStream(new InputStreamReader(new FileInputStream("C:\\Documents and Settings\\Administrator\\桌面\\22.txt"),"UTF-8"))//目前这个地方报错,应该如何修改呢
fws=new BufferedOutputStream(new OutputStreamWriter(new FileOutputStream("C:\\Documents and Settings\\Administrator\\桌面\\11.txt"),"UTF-8"));//目前这个地方报错,应该如何修改呢

byte[] bt=new byte[1024];
int len=0;
while((len=frs.read(bt))!=-1){
fws.write(bt,0,len);
}

} catch (Exception e) {
throw new RuntimeException("读取错误");
}finally{
try {
if(frs!=null)
frs.close();
} catch (Exception e2) {
throw new RuntimeException("读错误");
}


try {
if(fws!=null)
fws.close();
} catch (Exception e3) {
throw new RuntimeException("写错误");
}
}
}


我的思路是以utf-8的编码从文件中读取一定的字节数(数组)放入缓冲区内,然后以utf-8再写入文件

------解决方案--------------------
楼上正解哦~~~~