pub struct FileUtil;Expand description
文件工具结构体
Implementations§
Source§impl FileUtil
impl FileUtil
Sourcepub fn list(path: &Path, recurse: bool) -> Vec<String>
pub fn list(path: &Path, recurse: bool) -> Vec<String>
罗列指定路径下的子目录及文件。
参数 path 是要罗列内容的目标路径。
参数 recurse 决定是否以递归方式罗列子文件夹内的内容。
返回值是一个包含所有子目录及文件路径的 Vec<String>。
如果在读取目录时发生错误,将返回一个空的 Vec。
Sourcepub fn read_string(path: &Path) -> Result<String, Error>
pub fn read_string(path: &Path) -> Result<String, Error>
读取本地文件内容并以UTF - 8字符串形式返回。
参数 path 是要读取的文件路径。
如果文件成功打开并读取,将返回包含文件内容的 String。
如果在打开或读取文件时发生I/O错误,将返回对应的 io::Error。
Sourcepub fn read_bytes(path: &Path) -> Result<Vec<u8>, Error>
pub fn read_bytes(path: &Path) -> Result<Vec<u8>, Error>
读取本地文件内容并以字节数组形式返回。
参数 path 是要读取的文件路径。
如果文件成功打开并读取,将返回包含文件内容的 Vec<u8>。
如果在打开或读取文件时发生I/O错误,将返回对应的 io::Error。
Sourcepub fn write_string(path: &Path, content: String) -> Result<(), Error>
pub fn write_string(path: &Path, content: String) -> Result<(), Error>
将给定的字符串内容以覆盖方式写入到指定路径的文本文件。
参数 path 是要写入的文件路径。
参数 content 是要写入文件的字符串内容。
如果文件成功创建并写入内容,将返回 Ok(())。
如果在创建或写入文件时发生I/O错误,将返回对应的 io::Error。
Auto Trait Implementations§
impl Freeze for FileUtil
impl RefUnwindSafe for FileUtil
impl Send for FileUtil
impl Sync for FileUtil
impl Unpin for FileUtil
impl UnwindSafe for FileUtil
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more