问题记录-JAVA INPUTSTREAM读取数据问题
原代码:从oss上下载文件的时候,经常出现下载的文件下载不全的问题
InputStream inputStream = ossTool.downloadFile(downloadFilename);
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
byte[] b = new byte[bufferedInputStream.available()];
bufferedInputStream.read(b);
修改成下面的代码就可以正常下载了
InputStream inputStream = ossTool.downloadFile(downloadFilename);
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
byte[] b = new byte[1024*10];
int bytesRead = 0;
while((bytesRead = bufferedInputStream.read(b)) > -1){
outputStream.write(b, 0, bytesRead);
}