[英]Saving a file relative to working directory
我正在编写一个程序,可从ftp下载文件,我希望将文件放置在工作目录中的“文件”文件夹中,但是我不确定如何更改输出流来执行此操作。
这是我的代码:
String remoteFile1 = f.getName();
System.out.println(remoteFile1);
File downloadFile1 = new File(fileName);
OutputStream outputStream1 = new BufferedOutputStream(new FileOutputStream(downloadFile1));
boolean success = client.retrieveFile(remoteFile1, outputStream1);
outputStream1.close();
if (success) {
System.out.println(fileName + " has been downloaded successfully.");
}
我不确定更改目录需要编辑哪一部分。
请尝试更改您的fileName
以包括目录名称(“文件”),例如(由于@MadProgrammer):
File downloadFile1 = new File("files/", fileName); // Modify this line
另外,如果该目录不存在,请在开头添加以下代码:
new File("files").mkdirs();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.