工具方法
public static Path copy(File source, File target, boolean isOverride) throws IOException {
return Files.copy(source.toPath(), target.toPath(), isOverride ? StandardCopyOption.REPLACE_EXISTING : StandardCopyOption.COPY_ATTRIBUTES);
}
public static Path copy(String source, String target, boolean isOverride) throws IOException {
return copy(new File(source), new File(target), isOverride);
}
引用的类
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
相关方法
【java工具方法】复制目录或文件
示例
public static void main(String[] args) {
String source = "D:\\imgPath\\ewm.jpg";
String target = "D:\\imgPath\\ewm2.jpg";
try {
copy(source, target, true);
} catch (IOException e) {
e.printStackTrace();
}
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-25920.html