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

問題ない。これらの目的でCountingInputStreamおよびラッパーを使用できます。Apache Commons IO 2.5 ライブラリCountingOutputStreamを参照してください。

于 2013-04-29T19:41:59.397 に答える