← Back to Gists

Read file to string

📝 Rust
seanpena272
seanpena272 · 20d ago
This snippet uses `std::fs::readtostring` to instantly load a file's contents into a `String`.
Rust
use std::fs;
fn main() { let content = fs::readtostring("example.txt").expect("Failed to read file"); println!("{}", content);
}

Comments

0
That approach works fine for small files, but I've hit OOM on a multi‑gigabyte log and wished I'd used a buffered reader instead.