2011-05-03 2 views
8

파일을 FTP 서버에서 다운로드하는 간단한 FTPClient 클래스가 있습니다. 또한 다운로드 진행 상황을 모니터링해야하지만 방법이 표시되지 않습니다. 실제 다운로드 한 파일의 기능은 내가 다운로드 진행 상황을 모니터링 할 수있는 방법 Apache Commons FTPClient를 사용하여 진행 상황 모니터링

(your ftp client name).retrieveFile(arg1,arg2);

의 간단한 함수인가?

감사합니다. Anon.

+0

"해시"기능과 동등한 기능이 필요합니다. 그 기능이 무엇인지 모릅니다. – duffymo

+0

copyStreamAdapter에 대한 내용을 읽었지만 그에 대한 자세한 내용은 알지 못합니다. –

답변

18

CountingOutputStream이 필요합니다 (Commons IO에서 볼 수 있듯이 : http://commons.apache.org/io/api-release/index.html). 당신은 ..

편집을, 그 중 하나를 만들고 그 안에 당신의 대상의 OutputStream를 포장하고 당신은 다운로드 진행 상황을 모니터링하는 수요에 bytecount가를 확인할 수 있습니다

int size; 
String remote, local; 

// do some work to initialize size, remote and local file path 
// before saving remoteSource to local 
OutputStream output = new FileOutputStream(local); 
CountingOutputStream cos = new CountingOutputStream(output){ 
    protected void beforeWrite(int n){ 
     super.beforeWrite(n); 

     System.err.println("Downloaded "+getCount() + "/" + size); 
    } 
}; 
ftp.retrieveFile(remote, cos); 

output.close(); 

: 당신은 같은 것을 할 것 프로그램이 멀티 스레드 인 경우 별도의 스레드 (예 : GUI 프로그램)를 사용하여 진행 상황을 모니터 할 수 있지만 모든 응용 프로그램 별 세부 사항입니다.

+1

예를 볼 수 있습니까? –

관련 문제