[英]Progress of dataOutputStream.readFully
I'm receiving a file using dataInputStream.readFully, so i'd like to show the progress of the transmision.我正在使用 dataInputStream.readFully 接收文件,所以我想显示传输的进度。 Is it possible to know the progress of readFully method?
是否可以知道 readFully 方法的进度? Thank you.
谢谢你。
No - the whole point is that it's a single call to make it simpler to read.不 - 重点是它是一个单一的调用,使其更易于阅读。
If you want to read more gradually (eg to update a progress bar) you can just read a chunk at a time with InputStream.read(byte[], int, int)
in a loop until you've read all the data.如果您想逐步阅读(例如更新进度条),您可以使用
InputStream.read(byte[], int, int)
在循环中一次读取一个块,直到您读取所有数据。 For example:例如:
byte[] data = new byte[bytesToRead];
int offset = 0;
int bytesRead;
while ((bytesRead = stream.read(data, offset, data.length - offset)) > -1) {
offset += bytesRead;
// Update progress indicator
}
This is just like the JDK 8 code for readFully
, but with progress indication in the loop.这就像JDK 8 的
readFully
代码,但在循环中有进度指示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.