//结果报错StringIndexOutOfBoundsException,为什么不能直接用bfs.read(bytes),length的作用是什么?
public class Demo04 {
public static void main(String[] args) {
long start = System.currentTimeMillis();
try {
FileInputStream fis = new FileInputStream("1.txt");
BufferedInputStream bfs = new BufferedInputStream(fis);
byte[] bytes = new byte[1024];
// int length = 0;
// while ((length = bfs.read(bytes)) > 0) {
// System.out.println(new String(bytes, 0, length));
// }
while ((bfs.read(bytes)) > 0) {
System.out.println(new String(bytes, 0, bfs.read(bytes)));
}
bfs.close();
fis.close();
} catch (FileNotFoundException e) {
} catch (IOException e) {
e.printStackTrace();
}
long end = System.currentTimeMillis();
System.out.println(end - start);
}
}