0

我有一个 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();
           }

     }
4

1 回答 1

1

没问题。您可以将CountingInputStreamCountingOutputStream包装器用于这些目的。请参阅Apache Commons IO 2.5 库

于 2013-04-29T19:41:59.397 回答