头条地址:https://www.ixigua.com/i6765442674582356483
B站地址:https://www.bilibili.com/video/av78062009?p=1
网易云课堂地址:https://study.163.com/course/introduction.htm?courseId=1209596906#/courseDetail?tab=1
将文件读取成二进制,使用read函数
use std::fs;
fn main() {
let context = fs::read("tt").unwrap();
println!("context: {:#?}", context);
}
将文件读取成字符串
use std::fs;
fn main() {
let context = fs::read_to_string("tt").unwrap();
println!("context: {}", context);
}
use std::io;
use std::fs;
use std::path::Path;
fn visit_dirs(dir: &Path) -> io::Result<()> {
if dir.is_dir() {
for entry in fs::read_dir(dir)? {
let entry = entry?;
let path = entry.path();
if path.is_dir() {
visit_dirs(&path)?;
} else {
let c = fs::read_to_string(path).unwrap();
println!("file = {}", c);
}
}
}
Ok(())
}
fn main() {
//let context = fs::read("tt").unwrap();
//println!("context: {:#?}", context);
//let context = fs::read_to_string("tt").unwrap();
//println!("context: {}", context);
visit_dirs(Path::new("./test")).unwrap();
}