Read lines from a file

    0

    0

    Giovanny Gongora

    Codiga's Rust Recipes

    print them in terminal

    use std::fs::File;
    use std::io::{Write, BufReader, BufRead, Error};
    
    fn main() -> Result<(), Error> {
      let path = "lines.txt";
      let mut output = File::create(path)?;
      write!(output, "Rust Fun")?;
      let input = File::open(path)?;
      let buffered = BufReader::new(input);
      for line in buffered.lines() {
        println!("{}", line?);
      }
      Ok(())
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.