I'm using Apache Commons ftp library on Android. How it is possible to know the amount of data transferred during upload or download of a file and show it on a pr开发者_如何学运维ogress dialog?
Maybe this code can point you in the right direction:
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) { ... }
精彩评论