Skip to content

How to Read a File in Rust

If you need to read a file in Rust, then you can use the fs package from the standard library:

use std::fs; fn main() { let contents = fs::read_to_string(filename) .expect("Something went wrong reading the file"); println!("With text:\n{}", contents); }
Code language: Rust (rust)

See also  How to find the number of trailing zeros of N in Rust
Tags:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x