Kivanc Gunalp 68f8369cb4 Harden file_io exercises: remove magic number, dedupe paths
- file_io3: replace the hardcoded expected file size (117) with
  SAMPLE_TEXT.len(), so the check is derived from the actual content
  instead of an unexplained magic number.
- file_io3: use create_dir_all instead of create_dir, and add a
  sample_file_path() helper shared by main/create_required_files/
  file_cleanup to avoid three separate ad-hoc path constructions.
- file_io1/file_io2: hoist the sample text into a SAMPLE_TEXT constant
  used by both the exercise and its solution, removing duplicated
  literals.

No behavioral change: all three solutions were rebuilt and run
locally, producing identical output (file size still 117, permissions
still non-readonly) with no leftover files.
2026-07-26 15:27:53 +00:00
..
2026-07-26 15:09:01 +00:00

File IO

Rust provides several file I/O functions in the standard library. Buffered reads and writes provide better performance by reducing the number of underlying system calls.

Learning goals

  • file_io1 — Read an entire file into memory with fs::read_to_string and handle the Result it returns instead of unwrapping blindly, so you get comfortable with the basic "open, read, handle the error" pattern that most file I/O in Rust builds on.
  • file_io2 — Wrap a File in a BufReader to read it line by line and a BufWriter to write the transformed output, so you understand why buffering matters for I/O performance and how BufRead::lines lets you process input incrementally instead of loading it all at once.
  • file_io3 — Build a path with PathBuf, then call .metadata() to inspect properties like creation time, size, and permissions, so you can work with the filesystem safely across platforms without hardcoding path separators.

Further information

Here is the documentation for these functions in the standard library.