use std::fs;
https://doc.rust-lang.org/std/fs/index.html
use std::fs;
fn main() {
//fs::create_dir("/tmp/lala/121").unwrap();//mkdir
fs::create_dir_all("/tmp/lala/121").unwrap();//mkdir -p
let text = fs::read_to_string("./src/main.rs").expect("Read file failed!");//读取文件
println!("{}",text);
fs::write("/tmp/abc.rs",text);
fs::rename("/tmp/abc.rs", "/tmp/aaa.rs").unwrap();
for the_file in fs::read_dir("/tmp").unwrap() {
println!("{:?}",the_file.unwrap().path().to_str().unwrap());
}
}
https://doc.rust-lang.org/std/fs/struct.OpenOptions.html
https://doc.rust-lang.org/std/io/trait.Write.html
use std::fs::OpenOptions;
use std::io::Write;
fn main() {
let mut file_hd = OpenOptions::new()
.write(true)
.create(true)
.append(true)
.open("/tmp/11111.txt")
.unwrap();
file_hd.write(b"xxxxxxxxx\n").unwrap();
let s = "121\n".to_string();
file_hd.write(s.as_bytes()).unwrap();
let s = "qqq".to_string();
file_hd.write((&s).as_bytes()).unwrap();
}