【问题标题】:Not able to move .gitignore file from one directory to another无法将 .gitignore 文件从一个目录移动到另一个目录
【发布时间】:2021-11-12 10:30:09
【问题描述】:

我正在自动化一个特定的过程,在其中一个步骤中,我需要将.gitignore 文件从一个目录复制到另一个目录。 我正在使用 Apache 的 FileUtils 类来实现相同的目的,但是它无法识别这个特定的文件(它虽然存在于文件夹中)。该代码适用于其他文件。

这是我的代码:

public void copyFile(String destinationPath, String file) throws IOException {

    ClassPathResource classPathResourceAPIUtils = new ClassPathResource(file);
    String fileName = file.substring(file.lastIndexOf("/"));
    InputStream inputStreamapiUtils = classPathResourceAPIUtils.getInputStream();
    BufferedReader readUtils = new BufferedReader(new InputStreamReader(inputStreamapiUtils));
    List<String> utilsLines = readUtils.lines().collect(Collectors.toList());
    FileUtils.writeLines(new File(destinationPath+fileName), utilsLines, false);
}

【问题讨论】:

标签: java file apache-commons


【解决方案1】:

你为什么要重写文件。只需使用:

Files.move(from, to, StandardCopyOption.REPLACE_EXISTING)

Files.copy(from, to, StandardCopyOption.REPLACE_EXISTING)

【讨论】:

    猜你喜欢
    • 2014-12-04
    • 2017-07-20
    • 2021-06-16
    • 1970-01-01
    • 1970-01-01
    • 2019-09-26
    • 1970-01-01
    • 2016-06-09
    • 2016-04-04
    相关资源
    最近更新 更多