{"record":{"id":"bb668855e543d6fc","repo":"chinabugotech/hutool","slug":"file-not-exist","errorCode":null,"errorMessage":"File not exist: {}","messagePattern":"File not exist: (.+?)","errorType":"exception","errorClass":"IORuntimeException","httpStatus":null,"severity":"error","filePath":"hutool-core/src/main/java/cn/hutool/core/io/FileUtil.java","lineNumber":1137,"sourceCode":"\t\tAssert.notNull(src, \"Source File is null !\");\n\t\tAssert.notNull(dest, \"Destination File or directiory is null !\");\n\t\treturn copyFile(src, dest.toPath(), options).toFile();\n\t}\n\n\t/**\n\t * 通过JDK7+的 Files#copy(Path, Path, CopyOption...) 方法拷贝文件\n\t *\n\t * @param src     源文件\n\t * @param dest    目标文件或目录，如果为目录使用与源文件相同的文件名\n\t * @param options {@link StandardCopyOption}\n\t * @return 目标文件\n\t * @throws IORuntimeException IO异常\n\t */\n\tpublic static File copyFile(File src, File dest, StandardCopyOption... options) throws IORuntimeException {\n\t\t// check\n\t\tAssert.notNull(src, \"Source File is null !\");\n\t\tif (false == src.exists()) {\n\t\t\tthrow new IORuntimeException(\"File not exist: \" + src);\n\t\t}\n\t\tAssert.notNull(dest, \"Destination File or directiory is null !\");\n\t\tif (equals(src, dest)) {\n\t\t\tthrow new IORuntimeException(\"Files '{}' and '{}' are equal\", src, dest);\n\t\t}\n\t\treturn copyFile(src.toPath(), dest.toPath(), options).toFile();\n\t}\n\n\t/**\n\t * 复制文件或目录<br>\n\t * 如果目标文件为目录，则将源文件以相同文件名拷贝到目标目录\n\t *\n\t * @param srcPath    源文件或目录\n\t * @param destPath   目标文件或目录，目标不存在会自动创建（目录、文件都创建）\n\t * @param isOverride 是否覆盖目标文件\n\t * @return 目标目录或文件\n\t * @throws IORuntimeException IO异常\n\t */","sourceCodeStart":1119,"sourceCodeEnd":1155,"githubUrl":"https://github.com/chinabugotech/hutool/blob/8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442/hutool-core/src/main/java/cn/hutool/core/io/FileUtil.java#L1119-L1155","documentation":"FileUtil.copyFile(File src, File dest, StandardCopyOption...) delegates to NIO Files.copy after preconditions. It verifies the source exists; if src does not exist it throws IORuntimeException(\"File not exist: {}\") before attempting the OS-level copy.","triggerScenarios":"Calling FileUtil.copyFile where the source File does not exist (deleted, wrong path, never created).","commonSituations":"Source path from configuration is wrong or stale; a race where src is removed between your check and the call; a typo in the source path; copying before the source is generated.","solutions":["Verify src.exists() (or FileUtil.isFile(src)) immediately before calling copyFile.","Re-check the source path spelling and that it points to a generated file.","On failure, surface the absolute path in your own error for faster diagnosis."],"exampleFix":"// before\nFileUtil.copyFile(src, dest); // throws if src missing\n\n// after\nif (!src.exists()) {\n    throw new FileNotFoundException(\"source missing: \" + src);\n}\nFileUtil.copyFile(src, dest);","handlingStrategy":"validation","validationCode":"if (src != null && src.exists()) {\n    FileUtil.copyFile(src, dest, options);\n} else {\n    throw new java.io.FileNotFoundException(\"source missing: \" + src);\n}","typeGuard":"static boolean isCopyableSource(File f) {\n    return f != null && f.isFile();\n}","tryCatchPattern":"try {\n    return FileUtil.copyFile(src, dest, options);\n} catch (IORuntimeException e) {\n    if (e.getMessage().startsWith(\"File not exist\")) {\n        // source vanished: regenerate or report\n    }\n    throw e;\n}","preventionTips":["Verify src.exists() immediately before copyFile().","Re-check source paths from config at runtime.","Generate the source file before attempting to copy it."],"tags":["io","file","copy","validation"],"backgroundTag":null,"analyzedSha":"8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442","analyzedAt":"2026-08-14T04:01:12.892Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}