std::fs::OpenOptions
.open()
is working fine until I downloaded a crate directories
. I've tried removing the .toml dependencies and changing project but still receiving the same error using OpenOptions
. Using std::fs::File
.create()
.open()
seems to works just fine.
This is the output: Err(Os { code: 87, kind: InvalidInput, message: "The parameter is incorrect." })
The exact code used for testing in new project.
fn main() {
let r = std::fs::OpenOptions::new()
.create_new(true)
.open("foo.txt");
println!("What is this bug: {:?}", r);
}
Rust version 1.59.0
CodePudding user response:
The file must be opened with write or append access in order to create a new file. -- create_new docs
This works:
fn main() {
let r = std::fs::OpenOptions::new()
.create_new(true).write(true)
.open("foo.txt");
println!("What is this bug: {:?}", r);
}