gpt4 book ai didi

java - 我正在尝试下载我的网络服务器上的 pdf 文件,但是下载时我的文件已损坏

转载 作者:行者123 更新时间:2023-12-02 13:37:06 25 4
gpt4 key购买 nike

private Boolean downloadAndSaveFile(String server, int portNumber,String user, String password) throws IOException {

FTPClient ftp = null;
// path of a file which is on a web server
String remoteFile1 = "/public_html/1/c language/Unit_1_HTML_and_Forms.pdf";
// Path of my device
File downloadFile1 = new File("/storage/emulated/0/a/new.pdf");
try {
ftp = new FTPClient();
ftp.connect(server, portNumber);
ftp.login(user, password);
ftp.setFileType(FTP.BINARY_FILE_TYPE);
ftp.enterLocalPassiveMode();
System.out.println("Reached passive");
OutputStream outputStream1 = new BufferedOutputStream(new FileOutputStream(downloadFile1));
System.out.println("Stream Created");
boolean success = ftp.retrieveFile(remoteFile1, outputStream1);
System.out.println(success);
return true;
} catch(Exception e) {
System.out.println(e);
} finally {
if (ftp != null) {
ftp.logout();
ftp.disconnect();
}
}
return true;
}

最佳答案

我认为 retriveFile(...) 不会关闭流。返回 true 后尝试刷新并关闭它(outputStream1)

关于java - 我正在尝试下载我的网络服务器上的 pdf 文件,但是下载时我的文件已损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42928534/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com