Home > Back-end >  OS error 87 "The parameter is incorrect." on std::fs::OpenOptions
OS error 87 "The parameter is incorrect." on std::fs::OpenOptions

Time:04-06

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);
}
  • Related