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

     }

最佳答案

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

关于java - BOS/BIS取得进展,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16286751/

10-09 19:43