use std::io::BufRead;
use std::io::BufReader;
use std::fs::File;
use std::io::Read;
fn main() {
let f = File::open("input.kt").expect("open() failed");
let mut reader = BufReader::new(f);
let mut buffer = [0; 1];
loop {
match reader.read(&mut buffer) {
Ok(x) => {
if x != 0 {
println!("{}", buffer[0] as char)
}
else {
break;
}
}
Err(y) => panic!("read() failed"),
};
}
}
BufReader 结构实现了 BufRead trait,它继承自 Read,它有一个 read 方法: