Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Working with Files | Rust Fundamentals lesson | BraveProgrammer
  1. Courses
  2. /
  3. Rust Fundamentals

Lesson 29 of 50

·rust

Working with Files

18 minutes

Course progress58%

Working with Files

Use std::fs for file I/O.

use std::fs::File;
use std::io::{self, Write, Read};

fn main() -> io::Result<()> {
    let mut  = File::(\
file
create
"example.txt\")?; file.write_all(b\"Hello, file!\")?; let mut contents = String::new(); File::open(\"example.txt\")?.read_to_string(&mut contents)?; println!(\"File contains: {}\", contents); Ok(()) }
Make it stickPractice what you've learned1 quiz · 1 practical test · Optional activities from Rust FundamentalsBrowse activities
Previous lessonDocumentation with Cargo DocContinue to lesson 30Command Line ArgumentsBack to Rust Fundamentals curriculum