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

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. Rust Fundamentals

Lesson 29 of 50 · rust

Working with Files

Duration: 18 minutes

Working with Files\n\nUse std::fs for file I/O.\n\nrust\nuse std::fs::File;\nuse std::io::{self, Write, Read};\n\nfn main() -> io::Result<()> {\n let mut file = File::create(\"example.txt\")?;\n file.write_all(b\"Hello, file!\")?;\n let mut contents = String::new();\n File::open(\"example.txt\")?.read_to_string(&mut contents)?;\n println!(\"File contains: {}\", contents);\n Ok(())\n}\n\n

Previous: Documentation with Cargo DocNext: Command Line Arguments