gpt4 book ai didi

java - Java中的FileReader和ready方法

转载 作者:行者123 更新时间:2023-12-02 00:45:11 24 4
gpt4 key购买 nike

好的,所以我一次读取 40 mb 文件 1000 个字节。每次清空缓冲区时,我都会检查以确保 FileReader 仍然有要使用 read() 方法读取的数据。但是,当仍有尚未读取的位但流尚未准备好时,它会返回 false。我该如何规避这个问题?

if( !fileInput.ready() )
{

System.out.println(!fileInput.ready());
//empty the rest of the buffer into the output file
fileOutput.write( buffer.toString() );
fileOutput.flush();
doneProcessing = true;
}

最佳答案

我不知道你在哪里从 fileInput 读取并填充缓冲区。试试这个吧

FileOutputStream out =  ...
InputStream in = ..

int len = 0;
byte[] buffer = new byte[1024];

while ((len = in.read(buffer)) >= 0)
{
out.write(buffer, 0, len);
}

in.close();
out.close();

关于java - Java中的FileReader和ready方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5200760/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com