public void readFileByBytes(String fileName) {
File file = new File(fileName);
InputStream in = null;
try {
System.out.println("以字节为单位读取文件内容,一次读一个字节:");
// 一次读一个字节
in = new FileInputStream(file);
int tempbyte;
while ((tempbyte = in.read()) != -1) {
System.out.write(tempbyte);
}
in.close();
} catch (IOException e) {
e.printStackTrace();
return;
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e1) {
}
}
}
}
字节流读取文件
最新推荐文章于 2022-10-11 11:34:13 发布