使用文件字节流读取文件的标准方法:
public static void main(String[] args) throws Exception {
InputStream is = new FileInputStream("c:/test.txt");
byte[] mybyte = new byte[20];
int length = 0;//这个length是返回读取的实际的长度
while(-1 != (length=is.read(mybyte, 0, 20) )){
String str = new String(mybyte,0,length);//这里的length不能使用20,最后读取的可能没有20个字节,数据会多读
System.out.print(str);
}
is.close();
}