Class FileWriter
java.lang.Object
cloud.opencode.base.io.file.FileWriter
File Writer Utility
文件写入器
Fluent API for writing files with various options. Provides convenient methods for different writing scenarios.
用于写入文件的流式API。 提供适用于不同写入场景的便捷方法。
Features | 主要功能:
- Fluent API - 流式API
- Charset configuration - 字符集配置
- Append mode support - 追加模式支持
- Create parent directories - 创建父目录
Usage Examples | 使用示例:
// Write string
FileWriter.of(path).write("Hello World");
// Append content
FileWriter.of(path).append().write("More content");
// Write with charset
FileWriter.of(path).charset(StandardCharsets.ISO_8859_1).write(content);
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 TypeMethodDescriptionappend()Enables append mode 启用追加模式append(boolean append) Sets append mode 设置追加模式Gets a buffered writer 获取缓冲写入器Gets an output stream 获取输出流Sets the charset 设置字符集getPath()Gets the path 获取路径Disables automatic parent directory creation 禁用自动创建父目录static FileWriterCreates a file writer for the given path string 为给定路径字符串创建文件写入器static FileWriterCreates a file writer for the given path 为给定路径创建文件写入器voidwrite(byte[] bytes) Writes byte array to file 写入字节数组到文件voidwrite(CharSequence content) Writes string to file 写入字符串到文件voidwriteLines(Iterable<? extends CharSequence> lines) Writes lines to file 写入行到文件
-
Method Details
-
of
Creates a file writer for the given path 为给定路径创建文件写入器- Parameters:
path- the file path | 文件路径- Returns:
- file writer | 文件写入器
-
of
Creates a file writer for the given path string 为给定路径字符串创建文件写入器- Parameters:
path- the file path string | 文件路径字符串- Returns:
- file writer | 文件写入器
-
charset
Sets the charset 设置字符集- Parameters:
charset- the charset | 字符集- Returns:
- this | 当前对象
-
append
-
append
Sets append mode 设置追加模式- Parameters:
append- whether to append | 是否追加- Returns:
- this | 当前对象
-
noCreateParents
Disables automatic parent directory creation 禁用自动创建父目录- Returns:
- this | 当前对象
-
write
public void write(byte[] bytes) Writes byte array to file 写入字节数组到文件- Parameters:
bytes- the content | 内容
-
write
Writes string to file 写入字符串到文件- Parameters:
content- the content | 内容
-
writeLines
Writes lines to file 写入行到文件- Parameters:
lines- the lines | 行
-
asBufferedWriter
Gets a buffered writer 获取缓冲写入器- Returns:
- buffered writer | 缓冲写入器
-
asOutputStream
-
getPath
-