首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

帮忙看上这段读取字节流的代码哪里出有关问题了

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

帮忙看下这段读取字节流的代码哪里出问题了
本帖最后由 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再写入文件
[解决办法]
楼上正解哦~~~~

热点排行