import java.io.File; import java.io.FileInputStream; import java.io.IOException;
public class ioTest {
public static void main(String[] args) {
File file=new File("f:"+File.separator+"test.txt");
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
byte[] b = new byte[2];
int num = 0;
while((num = fis.read(b))!=-1){
System.out.print("******"+num);
System.out.println("--------"+new String(b,0,num));
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
******2--------先
******2--------休
******2--------息
******2--------吧
******1--------1
总结:
1.String(byte[] byte,int start,int length)的length是num的长度
原文:http://www.cnblogs.com/bky8652362/p/5372880.html