我有一个带有 BufferedInputStream 和 BufferedOutputStream 的上传,现在我想获得此上传的百分比进度。
如何获得这个?
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try
{
URL url = new URL( sb.toString() );
URLConnection urlc = url.openConnection();
bos = new BufferedOutputStream( urlc.getOutputStream() );
bis = new BufferedInputStream( new FileInputStream( source ) );
int i;
int progress = 0;
while ((i = bis.read()) != -1)
{
bos.write( i );
//how to get the progress here?!
}
}
finally
{
if (bis != null)
try
{
bis.close();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
if (bos != null)
try
{
bos.close();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
最佳答案
没问题。您可以使用 CountingInputStream
和 CountingOutputStream
包装器来实现这些目的。请参阅Apache Commons IO 2.5 library .
关于java - BOS/BIS 取得进展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16286751/