How to Use std

:fs for File System Operations

Use the std::fs module to read, write, and delete files in Rust by calling its functions and handling the Result.

Use the std::fs module to read, write, and manage files by calling its functions with a file path and handling the resulting Result.

use std::fs;

fn main() {
    let contents = fs::read_to_string("hello.txt")
        .expect("Failed to read file");
    println!("{contents}");

    fs::write("hello.txt", "Hello, world!")
        .expect("Failed to write file");

    fs::remove_file("hello.txt")
        .expect("Failed to remove file");
}