Added ability to read file by line

This commit is contained in:
Daniel Jones 2023-03-16 21:10:15 -05:00
parent b323604f01
commit 304e5aed6b
2 changed files with 16 additions and 2 deletions

View File

@ -1,3 +1,16 @@
fn main() { use std::fs::File;
println!("Hello, world!"); use std::io::prelude::*;
use std::env;
fn main() -> std::io::Result<()> {
let args: Vec<String> = env::args().collect();
let filename = &args[1];
let mut file = File::open(filename).expect("cannot open file.");
let mut contents = String::new();
file.read_to_string(&mut contents).expect("unreadable file.");
println!("{}", contents);
Ok(())
} }

1
test Normal file
View File

@ -0,0 +1 @@
this is a test