为什么我收到以下异常:
Exception in thread "main" java.io.IOException: Push back buffer is full
at java.io.PushbackInputStream.unread(PushbackInputStream.java:232)
at java.io.PushbackInputStream.unread(PushbackInputStream.java:252)
at org.tests.io.PushBackStream_FUN.read(PushBackStream_FUN.java:32)
at org.tests.io.PushBackStream_FUN.main(PushBackStream_FUN.java:43)
Run Code Online (Sandbox Code Playgroud)
在这段代码中:
public class PushBackStream_FUN {
public int write(String outFile) throws Exception {
FileOutputStream outputStream = new FileOutputStream(new File(outFile));
String str = new String("Hello World");
byte[] data = str.getBytes();
outputStream.write(data);
outputStream.close();
return data.length;
}
public void read(String inFile, int ln) throws Exception {
PushbackInputStream inputStream = new PushbackInputStream(new FileInputStream(new File(inFile)));
byte[] data = new byte[ln];
String str;
// read
inputStream.read(data);
str = …Run Code Online (Sandbox Code Playgroud) 参考stackoverflow问题,据说InputStream可以使用或通过使用来多次读取mark()和reset()提供.InputStreamPushbackInputStream
在所有这些情况下,流的内容存储在字节数组中(即,文件的原始内容存储在主存储器中)并重复使用多次.
当文件大小超过内存大小时会发生什么?我认为这可能会铺平道路OutOfMemoryException.
有没有更好的方法多次读取流内容而不在本地存储流内容(即;在主存储器中)?
知道这个,请帮帮我.提前致谢.