在執(zhí)行任何任務(wù)之前想要將文件復制/備份到目標文件夾。(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));我嘗試使用以下過程::但出現(xiàn)錯誤:錯誤::文件類型中的方法復制(InputStream,OutputStream)不適用于參數(shù)(字符串,字符串)//Calling method in main::copyFiles(inputFile, archiveFolderPath);//Copy method :private static void copyFiles (String inputFile, String archiveFolderPath) throws IOException { Files.copy(inputFile, archiveFolderPath); }請建議替代解決方案,如“文件不適用于參數(shù)(字符串,字符串)”。
1 回答

蝴蝶不菲
TA貢獻1810條經(jīng)驗 獲得超4個贊
您可以在對文件執(zhí)行讀取或?qū)懭氩僮髦皬椭圃撐募?。例子?
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有關(guān)所有方法的詳細信息,請參閱javadoc copy。他們中的一些人期待CopyOption著爭論。CopyOption根據(jù)節(jié)目要求選擇合適的。
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
添加回答
舉報
0/150
提交
取消