gpt4 book ai didi

Java强制复制文件

转载 作者:行者123 更新时间:2023-12-02 00:34:04 26 4
gpt4 key购买 nike

我有一个复制文件的方法:

private static void copy(final String source, final String destination) {
try {
final File f1 = new File(source);
final File f2 = new File(destination);
final InputStream in = new FileInputStream(f1);
final OutputStream out = new FileOutputStream(f2);
final byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
} catch (final FileNotFoundException ignored) {
} catch (final IOException ignored) {}
}

有没有办法可以覆盖复制到目录时的“访问被拒绝”错误?

注意:我只需要 Windows 计算机。

最佳答案

没有。如果您使用的是 UNIX,则需要以具有目录写入权限的用户身份运行程序。只是好奇,为什么要覆盖文件系统权限?为什么不直接使用适当的权限呢?

关于Java强制复制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8272829/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com