我正在尝试使用 java.nio.file.Files 复制文件,如下所示:
Files.copy(cfgFilePath, strTarget, StandardCopyOption.REPLACE_EXISTING);
问题是 Eclipse 说“Files 类型中的方法 copy(Path, Path, CopyOption...) 不适用于参数 (File, String, StandardCopyOption)”
我在 Win7 x64 上使用 Eclipse 和 Java 7。我的项目设置为使用 Java 1.6 兼容性。
有没有解决方案,或者我是否必须创建类似的东西作为解决方法:
File temp = new File(target);
if(temp.exists())
temp.delete();
Thanks.
你需要通过Path
错误消息解释的参数:
Path from = cfgFilePath.toPath(); //convert from File to Path
Path to = Paths.get(strTarget); //convert from String to Path
Files.copy(from, to, StandardCopyOption.REPLACE_EXISTING);
假设你的strTarget
是一个有效的路径。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)