Java 在FTPClient中上载进度
我正在使用commons net FTPClient上载一些文件。Java 在FTPClient中上载进度,java,ftp-client,apache-commons-net,Java,Ftp Client,Apache Commons Net,我正在使用commons net FTPClient上载一些文件。 如何获取上传进度(现在上传的字节数) 谢谢当然可以,就用吧。下面您将找到一个文件检索的示例(从commons io wiki复制),因此您可以很容易地改变它 try { InputStream stO = new BufferedInputStream( ftp.retrieveFileStream("foo.bar"),
如何获取上传进度(现在上传的字节数) 谢谢当然可以,就用吧。下面您将找到一个文件检索的示例(从commons io wiki复制),因此您可以很容易地改变它
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(),
/* I'm using the UNKNOWN_STREAM_SIZE constant here, but you can use the size of file too */
org.apache.commons.net.io.CopyStreamEvent.UNKNOWN_STREAM_SIZE,
new org.apache.commons.net.io.CopyStreamAdapter() {
public void bytesTransferred(long totalBytesTransferred,
int bytesTransferred,
long streamSize) {
// Your progress Control code here
}
});
ftp.completePendingCommand();
} catch (Exception e) { ... }
我认为,也许我们最好使用CountingOutputStream,因为它似乎正是为了这个目的
这里有人回答说:你看到了吗?我使用了这个解决方案,方法public void ByTestTransferred(long TotalByTestTransferred,int ByTestTransferred,long streamSize)在每次传输字节后调用,我无法更新我的UI,因为它的线程中充斥着UI更新调用。我在安卓系统中使用过,任何人都可以帮助解释为什么会发生@Lukasz