Java读取文件内容(多个字节)
package com.ycy1;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class Test02 {
public static void main(String[] args) {
FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream("E:" + File.separator + "test.txt");
byte[] b = new byte[4];
int len = 0;
while ((len = fileInputStream.read(b)) != -1) {
String string = new String(b, 0, len);
System.out.println(string);
}
} catch (FileNotFoundException e) {
System.out.println(e.toString());
} catch (IOException e) {
System.out.println(e.toString());
} finally {
if (fileInputStream != null) {
try {
fileInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210129142244698.png)