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();
}
}