23.09 File IO

File I/O

Overview

Rust provides tools for reading from and writing to files using the std::fs module.

Topics

Examples

use std::fs;

let content = fs::read_to_string("example.txt")
    .expect("Failed to read file");
println!("{}", content);

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

Tags

#rust #fileio