1指定每次读2个字节
FileInputStream fis = new FileInputStream("c.txt");
int length;
byte[] bytes=new byte[2];
while ((length=fis.read(bytes))!=-1){
System.out.println("bytes = " + new String(bytes,0,length));
}
fis.close();
日志:
bytes = df
bytes = 6y
bytes = y6
bytes = 56
2 读写文件
System.out.println("start = " + new Date().toLocaleString());
FileInputStream fis = new FileInputStream("c.txt");
FileOutputStream fileOutputStream = new FileOutputStream("c1.txt");
int length;
byte[] bytes=new byte[2];
while ((length=fis.read(bytes))!=-1){
System.out.println("bytes = " + new String(bytes,0,length));
System.out.println("toLocaleString = " + new Date().toLocaleString());
fileOutputStream.write(bytes,0,length);
}
fis.close();
fileOutputStream.close();
System.out.p