ch09
This commit is contained in:
parent
10b29ad9cb
commit
e1246d346d
10 changed files with 60 additions and 0 deletions
18
ch09/fopen.rs
Normal file
18
ch09/fopen.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
use std::fs::File;
|
||||
use std::io::ErrorKind;
|
||||
|
||||
fn main() {
|
||||
let greeting_file_result = File::open("hello.txt");
|
||||
let greeting_file = match greeting_file_result {
|
||||
Ok(file) => file,
|
||||
Err(error) => match error.kind() {
|
||||
ErrorKind::NotFound => match File::create("hello.txt") {
|
||||
Ok(fc) => fc,
|
||||
Err(e) => panic!("Problem creating the file: {e:?}"),
|
||||
},
|
||||
_ => {
|
||||
panic!("Problem opening the file: {error:?}");
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue