请教一个关于InputStream read()的问题
java吧
全部回复
仅看楼主
level 11
真的是难- 楼主
今天敲一个小程序时 碰到一个问题想不通[委屈]
import java.io.*;
public class TestFileOutputStream {
public static void main(String[] args){
int b = 0;
try{
FileInputStream fis = new FileInputStream("D:\\Song-b\\ted.txt");
FileOutputStream fos = new FileOutputStream("D:\\Song-b\\ted5.txt");
while((b=fis.read())!=-1){
fos.write(b);
System.out.print(b+" ");
}
fis.close();
fos.close();
}catch(IOException e){
e.printStackTrace();
System.exit(-1);
}
System.out.println();
System.out.println("success");
}
}
2013年12月18日 09点12分 1
level 11
真的是难- 楼主
读取是一个字节一个字节的读取 汉字是两个字节 为什么write写入到文本的时候能成功写入汉字而不出现??的现象呢
2013年12月18日 09点12分 2
读取是一个字节一个字节的读取,汉字是两个字节,为什么write写入到文本的时候能成功写入汉字而不出现??的现象呢
2013年12月18日 09点12分
level 12
志愿者的来应战了 估计是解码格式匹配文本文档 会不会是unicode[酷]
2013年12月18日 09点12分 3
level 13
[咦]你这程序等同于复制
理论上复制也是一个一个字节复制的
2013年12月18日 10点12分 4
level 13
你尝试下只传输过去一半数据
2013年12月18日 10点12分 5
试了一下 传一半的时候是一个空格(记事本是这么现实的),再传过另一半就变成一个汉字了
2013年12月18日 12点12分
回复 追星探月 :其实不是空格
2013年12月18日 13点12分
回复 danycive :我觉得也是 用UltraEdit应该能显示吧 学校机房电脑只有记事本 当时也没看
2013年12月18日 13点12分
回复 danycive :在我电脑上试了一下 是个?
2013年12月18日 13点12分
level 11
用字符流
2013年12月18日 10点12分 6
[乖]我没问这个
2013年12月18日 12点12分
level 11
import java.io.*;
public class TestIO{
public static void main(String args[]) throws Exception{
FileInputStream in = new FileInputStream("d:/aa.txt");
FileOutputStream out = new FileOutputStream("d:/bb.txt");
byte[] buffer = new byte[1024];
int result = 0;
while((result=in.read(buffer))!=-1){
out.write(buffer,0,result);
}
out.flush();
out.close();
in.close();
}
}
2013年12月18日 10点12分 7
1