add: use BufReader for line by line reading
This commit is contained in:
+10
-7
@@ -1,22 +1,25 @@
|
||||
#![allow(unused_imports)]
|
||||
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader};
|
||||
use log::{debug, error, info, trace, warn};
|
||||
use plume_log::{PlumeBuilder, success};
|
||||
|
||||
fn main(){
|
||||
fn main() -> std::io::Result<()>{
|
||||
PlumeBuilder::new()
|
||||
.with_level(log::LevelFilter::Trace)
|
||||
.init()
|
||||
.expect("Failed to init the logger");
|
||||
|
||||
let args: Vec<String> = env::args().collect();
|
||||
let file_path = &args[1];
|
||||
info!("{}", file_path);
|
||||
info!("File: {}", &args[1]);
|
||||
let file = File::open(&args[1])?;
|
||||
let reader = BufReader::new(file);
|
||||
|
||||
let contents = fs::read_to_string(file_path)
|
||||
.expect("File can't be read");
|
||||
for line in reader.lines() {
|
||||
println!("+ {}", line?);
|
||||
}
|
||||
|
||||
println!("{}", contents);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user