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