Added ability to read file by line
This commit is contained in:
parent
b323604f01
commit
304e5aed6b
17
src/main.rs
17
src/main.rs
@ -1,3 +1,16 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use std::fs::File;
|
||||
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(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user