Function fsio::file::write_file
source · [−]Expand description
Creates and writes the raw data to the requested file path. If a file exists at that path, it will be overwritten.
Arguments
path
- The file pathdata
- The file raw content
Example
use crate::fsio::file;
use std::path::Path;
use std::str;
fn main() {
let file_path = "./target/__test/file_test/write_file/file.txt";
let mut result = file::write_file(file_path, "some content".as_bytes());
assert!(result.is_ok());
result = file::append_file(file_path, "\nmore content".as_bytes());
assert!(result.is_ok());
let data = file::read_file(file_path).unwrap();
assert_eq!(str::from_utf8(&data).unwrap(), "some content\nmore content");
}