import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class FileInputStreamMore {
public static void main(String[] args) {
FileInputStream fis = null;
try {
fis = new FileInputStream("io/zijieinfile");
/*
byte [] bytes = new byte[4];
int readCount = 0;
while ((readCount = fis.read(bytes)) != -1) {
System.out.print(new String(bytes, 0, readCount));
}
*/
// available()不太适合太大的文件,因为byte数组不能太大
byte [] bytes = new byte[fis.available()];
int readCount = fis.read(bytes);
System.out.println(new String(bytes, 0, readCount));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
javase:字节输入
最新推荐文章于 2023-08-25 15:25:01 发布