frx*_*x08 2 java ftp ftp-client apache-commons-net
我正在尝试将文件从我的Java应用程序传输到FTP服务器程序正常工作,文件被传输,但是当我在FTO文件夹中打开时,文件已损坏,我认为文件在文件丢失期间丢失传递.为什么?我该如何解决这个问题?
另一个问题,while如果我想停止文件上传,我怎么能停止?
谢谢大家!
我班里的代码:
FTPClient client = new FTPClient();
InputStream is = null;
//...
try{
client.connect(MY_FTP_URL);
client.login(USER, PASS);
InputStream is = new FileInputStream(file_path);
OutputStream os = client.storeFileStream(file_name);
byte[] buffer = new byte[1024];
int len;
//I use this way to check the transfer progress
while((len = is.read(buffer)) != -1){
os.write(buffer, 0, len);
os.flush();
}
os.close();
} catch (IOException e){
e.printStackTrace();
} finally{
try{
if(is != null){
is.close();
}
client.disconnect();
} catch(IOException e){
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2412 次 |
| 最近记录: |