- Learning Rust
- Paul Johnson Vesa Kaihlavirta
- 94字
- 2021-07-02 23:07:22
Reading from a file
Here, we are going to use std::io, std::io::prelude::* and std::fs::File. std::io is the standard input/output library, the * after prelude means to use anything in the prelude library, and std::fs is the filesystem library.
Filesystem calls are very platform-specific; Windows users use the likes of C://Users/Paul/Documents/My Documents for the user's home directory, whereas Linux and macOS machines would use ~/ for the user's home directory. If a path is not given for a file, the program will assume the file is in the same directory in which the binary resides.