转移了Android ftp字节

时间:2011-06-13 15:50:48

标签: android ftp

我在Android上使用Apache Commons ftp库。 如何知道在上传或下载文件期间传输的数据量并在进度对话框中显示?

2 个答案:

答案 0 :(得分:1)

也许这段代码可以指出正确的方向:

try {
  InputStream stO = new BufferedInputStream(ftp.retrieveFileStream("foo.bar"),
                ftp.getBufferSize());
  OutputStream stD = new FileOutputStream("bar.foo");

  org.apache.commons.net.io.Util.copyStream(stO, stD, ftp.getBufferSize(),
                CopyStreamEvent.UNKNOWN_STREAM_SIZE,
                new CopyStreamAdapter() {
                    public void bytesTransferred(long totalBytesTransferred,
                            int bytesTransferred,
                            long streamSize) {
                            // Your progress Control code here
                    }
        });
        ftp.completePendingCommand();
} catch (Exception e) { ... }

答案 1 :(得分:0)