{"record":{"id":"161378abfe1e3638","repo":"chinabugotech/hutool","slug":"file-not-exist-161378","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/file/FileCopier.java","lineNumber":175,"sourceCode":"\t * 2、源为文件，目标为不存在路径，则目标以文件对待（自动创建父级目录）比如：/dest/aaa，如果aaa不存在，则aaa被当作文件名\n\t * 3、源为文件，目标是一个已存在的文件，则当{@link #setOverride(boolean)}设为true时会被覆盖，默认不覆盖\n\t * 4、源为目录，目标为已存在目录，当{@link #setCopyContentIfDir(boolean)}为true时，只拷贝目录中的内容到目标目录中，否则整个源目录连同其目录拷贝到目标目录中\n\t * 5、源为目录，目标为不存在路径，则自动创建目标为新目录，然后按照规则4复制\n\t * 6、源为目录，目标为文件，抛出IO异常\n\t * 7、源路径和目标路径相同时，抛出IO异常\n\t * </pre>\n\t *\n\t * @return 拷贝后目标的文件或目录\n\t * @throws IORuntimeException IO异常\n\t */\n\t@Override\n\tpublic File copy() throws IORuntimeException{\n\t\tfinal File src = this.src;\n\t\tFile dest = this.dest;\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 (FileUtil.equals(src, dest)) {\n\t\t\tthrow new IORuntimeException(\"Files '{}' and '{}' are equal\", src, dest);\n\t\t}\n\n\t\tif (src.isDirectory()) {// 复制目录\n\t\t\tif(dest.exists() && false == dest.isDirectory()) {\n\t\t\t\t//源为目录，目标为文件，抛出IO异常\n\t\t\t\tthrow new IORuntimeException(\"Src is a directory but dest is a file!\");\n\t\t\t}\n\t\t\tif(FileUtil.isSub(src, dest)) {\n\t\t\t\tthrow new IORuntimeException(\"Dest is a sub directory of src !\");\n\t\t\t}\n\n\t\t\tfinal File subTarget = isCopyContentIfDir ? dest : FileUtil.mkdir(FileUtil.file(dest, src.getName()));\n\t\t\tinternalCopyDirContent(src, subTarget);\n\t\t} else {// 复制文件","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/chinabugotech/hutool/blob/8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442/hutool-core/src/main/java/cn/hutool/core/io/file/FileCopier.java#L157-L193","documentation":"FileCopier.copy() is the entry point that copies src to dest. As a precondition it asserts the source exists; if this.src does not exist it throws IORuntimeException(\"File not exist: {}\") before doing any work.","triggerScenarios":"Calling copy() on a FileCopier built with a source File that does not exist on disk.","commonSituations":"Source path misconfigured or stale; the file deleted before the copy runs; FileCopier constructed with a path for a file that has not been generated yet.","solutions":["Verify src.exists() before building or calling copy().","Construct the FileCopier only after confirming the source is present.","Surface the absolute src path in your own error for quicker diagnosis."],"exampleFix":"// before\nFile result = FileCopier.create(src, dest).copy(); // throws if src missing\n\n// after\nif (!src.exists()) {\n    throw new FileNotFoundException(\"source not found: \" + src.getAbsolutePath());\n}\nFile result = FileCopier.create(src, dest).copy();","handlingStrategy":"validation","validationCode":"if (src != null && src.exists()) {\n    return FileCopier.create(src, dest).copy();\n}\nthrow new java.io.FileNotFoundException(\"source not found: \" + src);","typeGuard":"static boolean isCopyableSource(File f) {\n    return f != null && f.exists();\n}","tryCatchPattern":"try {\n    return FileCopier.create(src, dest).copy();\n} catch (IORuntimeException e) {\n    if (e.getMessage().startsWith(\"File not exist\")) {\n        // source missing: regenerate or report\n    }\n    throw e;\n}","preventionTips":["Verify src.exists() before building/calling FileCopier.copy().","Construct the copier only after the source is confirmed present.","Surface the absolute src path in your own error for faster diagnosis."],"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"}