chinabugotech/hutool · error · IORuntimeException
File not exist: {}
Error message
File not exist: {} What it means
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.
Source
Thrown at hutool-core/src/main/java/cn/hutool/core/io/FileUtil.java:1137
Assert.notNull(src, "Source File is null !");
Assert.notNull(dest, "Destination File or directiory is null !");
return copyFile(src, dest.toPath(), options).toFile();
}
/**
* 通过JDK7+的 Files#copy(Path, Path, CopyOption...) 方法拷贝文件
*
* @param src 源文件
* @param dest 目标文件或目录,如果为目录使用与源文件相同的文件名
* @param options {@link StandardCopyOption}
* @return 目标文件
* @throws IORuntimeException IO异常
*/
public static File copyFile(File src, File dest, StandardCopyOption... options) throws IORuntimeException {
// check
Assert.notNull(src, "Source File is null !");
if (false == src.exists()) {
throw new IORuntimeException("File not exist: " + src);
}
Assert.notNull(dest, "Destination File or directiory is null !");
if (equals(src, dest)) {
throw new IORuntimeException("Files '{}' and '{}' are equal", src, dest);
}
return copyFile(src.toPath(), dest.toPath(), options).toFile();
}
/**
* 复制文件或目录<br>
* 如果目标文件为目录,则将源文件以相同文件名拷贝到目标目录
*
* @param srcPath 源文件或目录
* @param destPath 目标文件或目录,目标不存在会自动创建(目录、文件都创建)
* @param isOverride 是否覆盖目标文件
* @return 目标目录或文件
* @throws IORuntimeException IO异常
*/View on GitHub (pinned to 8870454b2a)
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.
Example fix
// before
FileUtil.copyFile(src, dest); // throws if src missing
// after
if (!src.exists()) {
throw new FileNotFoundException("source missing: " + src);
}
FileUtil.copyFile(src, dest); Defensive patterns
Strategy: validation
Validate before calling
if (src != null && src.exists()) {
FileUtil.copyFile(src, dest, options);
} else {
throw new java.io.FileNotFoundException("source missing: " + src);
} Type guard
static boolean isCopyableSource(File f) {
return f != null && f.isFile();
} Try / catch
try {
return FileUtil.copyFile(src, dest, options);
} catch (IORuntimeException e) {
if (e.getMessage().startsWith("File not exist")) {
// source vanished: regenerate or report
}
throw e;
} Prevention
- Verify src.exists() immediately before copyFile().
- Re-check source paths from config at runtime.
- Generate the source file before attempting to copy it.
When it happens
Trigger: Calling FileUtil.copyFile where the source File does not exist (deleted, wrong path, never created).
Common situations: 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.
Related errors
- File not exist: {}
- Not a regular file!
- File path is blank!
- Input must be a File
- Files '{}' and '{}' are equal
AI-assisted analysis of chinabugotech/hutool@8870454b2a (2026-08-14).
Data as JSON: /api/errors/bb668855e543d6fc.
Report an issue: GitHub.