亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Java 文件復制 - 如何備份/復制輸入文件到其他目標位置?

Java 文件復制 - 如何備份/復制輸入文件到其他目標位置?

皈依舞 2023-07-13 17:50:02
在執行任何任務之前想要將文件復制/備份到目標文件夾。(jdk-1.7) /*Input file path taken from properties file as string is :inputFilewhere-in inputFile is :C:\\Project\\input\\filename.txtDestination file path taken from properties file as string is : archiveFolderPath */  //Existing code : in mainif (inputFile != null) {readTextFile(new File(inputFile)); }// in readTextFile methodBufferedReader br = new BufferedReader(new FileReader(filename));我嘗試使用以下過程::但出現錯誤:錯誤::文件類型中的方法復制(InputStream,OutputStream)不適用于參數(字符串,字符串)//Calling method in main::copyFiles(inputFile, archiveFolderPath);//Copy method :private static void copyFiles (String inputFile, String   archiveFolderPath) throws IOException {    Files.copy(inputFile, archiveFolderPath); }請建議替代解決方案,如“文件不適用于參數(字符串,字符串)”。
查看完整描述

1 回答

?
蝴蝶不菲

TA貢獻1810條經驗 獲得超4個贊

您可以在對文件執行讀取或寫入操作之前復制該文件。例子:-


Path origin = Paths.get("/home/fm/source.txt");

Path destination = Paths.get("/home/fm/source.bak");


//Copy source.txt to source.bak

Files.copy(origin, destination, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);

Files有關所有方法的詳細信息,請參閱javadoc copy。他們中的一些人期待CopyOption著爭論。CopyOption根據節目要求選擇合適的。


https://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html https://docs.oracle.com/javase/7/docs/api/java/nio/file/StandardCopyOption.html#COPY_ATTRIBUTES


查看完整回答
反對 回復 2023-07-13
  • 1 回答
  • 0 關注
  • 134 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號