简体   繁体   English

错误:java.io.IOException:句柄无效

[英]Error: java.io.IOException: The handle is invalid

I am trying to move file from one location to another When i run the .jar through command prompt it's working fine but when jar has been trigger from Robot scheduler(with different service account) getting below error 我正在尝试将文件从一个位置移动到另一个位置,当我通过命令提示符运行.jar时,它工作正常,但是当从机器人调度程序(使用不同的服务帐户)触发jar时,出现以下错误

java.io.IOException: The handle is invalid
    at java.io.WinNTFileSystem.canonicalize0(Native Method)
    at java.io.WinNTFileSystem.canonicalize(Unknown Source)
    at java.io.File.getCanonicalPath(Unknown Source)
    at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:1076)
    at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:1040)

The method which i am using for fileMove is below 我用于fileMove的方法如下

public static Boolean fileMove(File source, String destination) {
    LOG.info(destination + File.separator + source.getName());
    LOG.info(source.getAbsolutePath());
    File dest = new File(destination + File.separator + source.getName());


     try {
         FileUtils.copyFile(source, dest);
         return FileUtils.contentEquals(source, dest) && Files.deleteIfExists(source.toPath());
     } catch (IOException e) {
         LOG.warn("IO Error Occurred during file Operations", e);
         return false;
     }
}

LOG.info(destination + File.separator + source.getName()) is logging below path //uk001/eucl/Email_Broker_Archive\\mime-message--7431406574003289236.eml LOG.info(destination + File.separator + source.getName())正在路径//uk001/eucl/Email_Broker_Archive\\mime-message--7431406574003289236.eml下记录
(destination=//uk001/eucl/Email_Broker_Archive, File.separator='\\', source.getName()=mime-message--7431406574003289236.eml (目的地= // uk001 / eucl / Email_Broker_Archive,File.separator ='\\',source.getName()= mime-message--7431406574003289236.eml

LOG.info(source.getAbsolutePath()) is logging below path LOG.info(source.getAbsolutePath())正在记录以下路径

\\uk001\\eucl\\Source\\0002\\mime-message--7431406574003289236.eml \\ uk001 \\ eucl \\ Source \\ 0002 \\ mime-message--7431406574003289236.eml

R/W Permission is there for both service account(cmd and Robot scheduler) and the application is running on windows server. 服务帐户(cmd和Robot Scheduler)都具有R / W权限,并且该应用程序正在Windows服务器上运行。

It seems to be an issue of File separator not matching the OS's file separator. 文件分隔符似乎与操作系统的文件分隔符不匹配是一个问题。

//uk001/eucl/Email_Broker_Archive\\mime-message--7431406574003289236.eml //uk001/eucl/Email_Broker_Archive\\mime-message--7431406574003289236.eml

Please replace and check if the \\ is the issue. 请更换并检查\\是否是问题。 Also, do an if check if the file exists before copying the file all the time. 另外,在始终复制文件之前,请先检查文件是否存在。

if (!Files.exists(dest)) {
    FileUtils.copyFile(source, dest);
    return FileUtils.contentEquals(source, dest) && Files.deleteIfExists(source.toPath());
//Modify the check above accordingly as the file exists check is already done.
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM