Class OpenTempFile
java.lang.Object
cloud.opencode.base.io.temp.OpenTempFile
Temp File Utility Class
临时文件工具类
Utility class for creating and managing temporary files and directories. Provides convenient methods for temp file operations.
用于创建和管理临时文件和目录的工具类。 提供便捷的临时文件操作方法。
Features | 主要功能:
- Create temp files and directories - 创建临时文件和目录
- Auto-delete temp files - 自动删除临时文件
- Cleanup old temp files - 清理过期临时文件
Usage Examples | 使用示例:
// Simple temp file
Path temp = OpenTempFile.createTempFile("data", ".tmp");
// Auto-delete temp file
try (AutoDeleteTempFile temp = OpenTempFile.createAutoDeleteTempFile("data", ".json")) {
temp.write(content);
} // Automatically deleted
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
- Since:
- JDK 25, opencode-base-io V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic intcleanupOldTempFiles(Path dir, Duration maxAge, String pattern) Cleans up old temporary files 清理过期临时文件static intcleanupOldTempFiles(Duration maxAge, String pattern) Cleans up all files matching pattern in temp directory 清理临时目录中匹配模式的所有文件static AutoDeleteTempFilecreateAutoDeleteTempFile(String prefix, String suffix) Creates an auto-delete temporary file 创建自动删除临时文件static AutoDeleteTempFilecreateAutoDeleteTempFile(Path dir, String prefix, String suffix) Creates an auto-delete temporary file in specified directory 在指定目录创建自动删除临时文件static PathcreateTempDirectory(String prefix) Creates a temporary directory 创建临时目录static PathcreateTempDirectory(Path dir, String prefix) Creates a temporary directory in specified parent 在指定父目录创建临时目录static PathcreateTempFile(String prefix, String suffix) Creates a temporary file 创建临时文件static PathcreateTempFile(Path dir, String prefix, String suffix) Creates a temporary file in specified directory 在指定目录创建临时文件static PathcreateTempFileFromStream(InputStream input, String prefix, String suffix) Creates a temporary file from input stream 从输入流创建临时文件static PathGets the system temp directory 获取系统临时目录static booleanisInTempDirectory(Path path) Checks if a path is in the temp directory 检查路径是否在临时目录中
-
Method Details
-
createTempFile
-
createTempFile
-
createTempDirectory
-
createTempDirectory
-
createAutoDeleteTempFile
Creates an auto-delete temporary file 创建自动删除临时文件- Parameters:
prefix- the prefix | 前缀suffix- the suffix | 后缀- Returns:
- auto delete temp file | 自动删除临时文件
-
createAutoDeleteTempFile
Creates an auto-delete temporary file in specified directory 在指定目录创建自动删除临时文件- Parameters:
dir- the directory | 目录prefix- the prefix | 前缀suffix- the suffix | 后缀- Returns:
- auto delete temp file | 自动删除临时文件
-
createTempFileFromStream
Creates a temporary file from input stream 从输入流创建临时文件- Parameters:
input- the input stream | 输入流prefix- the prefix | 前缀suffix- the suffix | 后缀- Returns:
- temp file path | 临时文件路径
-
getTempDirectory
Gets the system temp directory 获取系统临时目录- Returns:
- temp directory path | 临时目录路径
-
cleanupOldTempFiles
-
cleanupOldTempFiles
-
isInTempDirectory
Checks if a path is in the temp directory 检查路径是否在临时目录中- Parameters:
path- the path | 路径- Returns:
- true if in temp dir | 如果在临时目录中返回true
-