spring - 在远程服务器java上读/写文件
问题描述
嗨,我想写入远程服务器中存在的文件我尝试使用此代码我无法读取文件的内容,但我找不到任何代码来编写任何帮助
FTPClient ftpClient = new FTPClient();
ftpClient.connect(server, port);
ftpClient.login(user, pass);
ftpClient.enterLocalPassiveMode();
ftpClient.setFileType(2);
List<String> list = new ArrayList<>();
String remoteFile1 = "/anomalies_t24/conf/trac.ini";
InputStream inputStream = ftpClient.retrieveFileStream(remoteFile1);
InputStreamReader isr = new InputStreamReader(inputStream);
BufferedReader br = new BufferedReader(isr);
list = br.lines().collect(Collectors.toList());
//list.forEach(System.out::println);
for (int i = 0; i < list.size(); i++) {
if (list.get(i).contains("projet.options =")) {
list.set(i, list.get(i) + "|" + nom);
break;
}
}
inputStream.close();
解决方案
如果您正在使用或想要使用 Apache Commons Net 3.6 FTPClient API,则使用以下方法附加文件:
public boolean appendFile(String remote, InputStream local) throws IOException
或者您可以从下面的 Apache Commons Net API 的 javadoc 链接中找到其他有用的方法:
https://commons.apache.org/proper/commons-net/apidocs/org/apache/commons/net/ftp/FTPClient.html
推荐阅读
- html - HTML 斜体和非斜体文本被渲染得太近
- api - 如果没有在 API 请求中指定端口号,服务器如何决定该请求是针对端口 80 还是 443
- c - 在C中使用free 3次后出现分段错误
- druid - 如何在德鲁伊中自动删除日志
- javascript - 没有变异道具的双 for 循环,VUE3
- python - 如何使用python解析这种文件?
- google-cloud-platform - 从 Google 更改电子邮件但继续使用 GCP
- mysql - 具有(错误)值的 Mysql 日期数据类型
- javascript - 地图函数中的对象解构
- scala - 无法下载流的播放迁移的依赖项(Scala/sbt)