This example uses the read_until function on BufReader. It gets the entire contents of the file, and places it into a vector of bytes.
use std::io::*;
use std::fs::File;
fn main() {
let file = File::open(
"/home/sam/programs/test.txt").unwrap();
let mut reader = BufReader::new(file);
let mut buf = vec![];
// Use read_until to read until EOF.
reader.read_until(u8::MIN, &mut buf);
println!(
"BYTES: {:?}", buf);
// Convert vector of bytes to string.
let data = String::from_utf8(buf).unwrap();
println!(
"STRING: {}", data);
}
BYTES: [111, 114, 97, 110, 103, 101, 32, 99, 97, 116, 13, 10]
STRING: orange cat