Advertisement
NLinker

Read and write file

Jul 7th, 2018
487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.38 KB | None | 0 0
  1. use std::fs::File;
  2. use std::io::Read;
  3. use std::io::Write;
  4.  
  5. fn main() {
  6.     let mut data = String::new();
  7.     let mut f = File::open("./README.md").unwrap();
  8.     f.read_to_string(&mut data).unwrap();
  9.     println!("{}", data);
  10.  
  11.     let mut data2 = format!("hello {}", data);
  12.     let mut f = File::create("./README.md").unwrap();
  13.     f.write_all(&mut data2.as_bytes()).unwrap();
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement