Non orthogonal std::fs::read vs std::fs::write?

std::fs::write("file.ext",&content);//writes, content to file.ext. If file.ext doesn't exist it creates it. That works.

Literally next line:

std::fs::read("file.ext");//gives error=> File doesn't exist. But the file exists.

I know where the problem is, the path to the read is incorrect that is, it is not pointing to the file, but if the path to the write in such form is correct, read should be able to deduce same path that file was created when using std::fs::write

Can you give us an example program that fails and which we can run for ourselves. Also, please add an unwrap or other error handling to write to verify that it did not encounter an IO error when writing.

I get this when I run that:

$ cargo run 
   Compiling bar v0.1.0 (/tmp/bar)
    Finished dev [unoptimized + debuginfo] target(s) in 0.33s
     Running `target/debug/bar`
Read file content
1 Like

Hi, yes, me too. I'm sorry for the confusion. I don't understand how it wasn't working before I've posted.

My guess is that it's some minor mistake somewhere.

1 Like

Must've been. Thank you for your time and help.