here is my code :
use std::fs::File;
use std::io::Read;
fn main() {
let filename = "hello.txt";
let f = File::open(filename);
let mut f = match f {
Ok(file) => file,
Err(error) => {panic!("{:?}", error);},
};
let mut x :String = "".to_sting();
f.read_to_string(&mut x).expect("some error occured");
println!("text was ::::::::: {}", x);
}
here is the "cargo run " output :
C:\Users\Dell\Desktop\rust\learn\file_io>cargo run
Compiling file_io v0.1.0 (file:///C:/Users/Dell/Desktop/rust/learn/file_io)
Finished dev [unoptimized + debuginfo] target(s) in 1.07s
Running `target\debug\file_io.exe`
thread 'main' panicked at 'Os { code: 2, kind: NotFound, message: "The system cannot find the file specified." }', src\main.rs:10:17
note: Run with `RUST_BACKTRACE=1` for a backtrace.
error: process didn't exit successfully: `target\debug\file_io.exe` (exit code: 101)
i can assure you file is present in same directory as binary " C:\Users\Dell\Desktop\rust\learn\file_io\target\debug\hello.txt"
its working when i provide absolute file path , but not with relative path