FileUtils.moveFile 多个文件后,文件所属不一致

在Linux系统中,使用Apache Commons IO的FileUtils.moveFile方法移动文件后,部分文件的所有者变为执行用户。问题源于当目标路径不存在时,FileUtils会先尝试复制再删除原文件,导致所有权变化。后续移动操作由于目标路径已存在,直接重命名成功,避免了所有权问题。
摘要由CSDN通过智能技术生成

问题描述

Linux 系统原文件所属user1, 使用user2 在move到另一个文件下后,新的文件夹下有一个文件所属为user2. 其它的都是user1.
moveFile通过org.apache.commons.io.FileUtils.moveFile();
权限没有问题,为什么移动后的文件所属不一致呢?

查看原码

    public static void moveFile(File srcFile, File destFile) throws IOException {
        if (srcFile == null) {
            throw new NullPointerException("Source must not be null");
        } else if (destFile == null) {
            throw new NullPointerException("Destination must not be null");
        } else if (!srcFile.exists()) {
            throw new FileNotFoundException("Source '" + srcFile + "' does not exist");
        } else if (srcFile.isDirectory()) {
            throw new IOException("Source '" + srcFile + "' is a directory");
        } else if (destFile.exists()) {
            throw new FileExistsException("Destination '
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值