Ich muss ein Stück Java-Code nachrüsten, der mit Java 1.6 kompatibel sein muss, und ich suche nach einer Alternative für Fileoutputstream in der folgenden Funktion. Ich benutze das apache.commons FTP-Paket.FileOutputStream Alternative für Java 1.6
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
FTPClient ftp = null;
public FTPFetch(String host, int port, String username, String password) throws Exception
{
ftp = new FTPClient();
ftp.setConnectTimeout(5000);
ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
int reply;
ftp.connect(host, port);
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply))
{
ftp.disconnect();
throw new Exception("Exception in connecting to FTP Server");
}
if (ftp.login(username, password))
{
ftp.setFileType(FTP.BINARY_FILE_TYPE);
ftp.enterLocalActiveMode();
} else
{
disconnect();
errorLog.fatal("Remote FTP Login Failed. Username or Password is incorrect. Please update in configuration file.");
System.exit(1);
}
}
try (FileOutputStream fos = new FileOutputStream(destination))
{
if (this.ftp.retrieveFile(source, fos))
{
return true;
} else
{
return false;
}
} catch (IOException e)
{
return false;
}
'FileOutputStream' existiert si nce JDK 1.0 – Berger
hinweis: 'if (condition) {return true; } else {return false; } 'ist dasselbe wie' return condition; ' –
Danke, ich habe den Code geändert, um das lokal zu beheben. – Tacitus86