首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >BOS/BIS取得进展

BOS/BIS取得进展
EN

Stack Overflow用户
提问于 2013-04-30 03:33:01
回答 1查看 219关注 0票数 0

我有一个带有BufferedInputStream和BufferedOutputStream的上传,现在我想要获得此上传的进度百分比。

如何获得这个??

代码语言:javascript
复制
     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();
           }

     }
EN

回答 1

Stack Overflow用户

发布于 2013-04-30 03:41:59

没问题。您可以使用CountingInputStreamCountingOutputStream包装器来实现这些目的。参见Apache Commons IO 2.5 library

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16286751

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档