summaryrefslogtreecommitdiff
path: root/meap/meap-code/ch2/ch2-read-file.rs
blob: 61143139ddde9dd3c83298a44eec881508d03280 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use std::fs::File;
use std::io::BufReader;
use std::io::prelude::*;

fn main() {
  let mut f = File::open("readme.md").unwrap();
  let mut reader = BufReader::new(f);

  let mut line = String::new();
  loop {
    let len = reader.read_line(&mut line).unwrap();

    if len == 0 {
      break
    }
    println!("{} ({} bytes long)", line, len);

    line.truncate(0);
  }

}