public class TestBufferedOutputStream{
public static void main(String args[])throws IOException{
BufferedInputStream bi=
new BufferedInputStream(new FileInputStream("1.txt"));
byte data[]=new byte[10];
while(bi.read(data)!=-1){
for(int i=0;i<data.length;i++){
System.out.print((char)data[i]);
//怎么结果不对?
}
}
bi.close();
}
}
1.txt里面的内容是:
1234567890
9876543210
程序最后显示:
1234567890
987654321098765432
我查jdk了,bi.read(data)方法最后是调用了FileInputStream的read(byte[] b,int off,int len);是不?
我对最后结果不明白,怎么多出了?看api也不懂。
一个英文的,一个翻译的:
http://apicode.gicp.net/class.do?api=selectByfatherIndex&father=255
http://apicodecn.gicp.net/class.do?api=selectByfatherIndex&father=255
1.txt包含的字节数并不是20个呀。