diff --git a/src/main.rs b/src/main.rs index e7a11a9..9bbe29b 100644 --- a/src/main.rs +++ b/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 = 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(()) } diff --git a/test b/test new file mode 100644 index 0000000..90bfcb5 --- /dev/null +++ b/test @@ -0,0 +1 @@ +this is a test