我正在自動化一個特定的程序,在其中一個步驟中,我需要將一個.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().collectors.toList()。
FileUtils.writeLines(new File(destinationPath fileName), utilsLines, false) 。
}
uj5u.com熱心網友回復:
你為什么要重寫檔案。只需使用:
Files.move(from, to, StandardCopyOption.REPLACE_EXISTING)
或者
Files.copy(from, to, StandardCopyOption.REPLACE_EXISTING)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/328095.html
標籤:
上一篇:盡管組件中存在屬性,但在規范檔案中被認定為未定義。用Karma在Angular中進行單元測驗-Jasmine
下一篇:React訪問檔案資料
