在执行任何任务之前想要将文件复制/备份到目标文件夹。(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
添加回答
举报
0/150
提交
取消