Skip to content

Instantly share code, notes, and snippets.

@eduardonunesp
Created January 4, 2022 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eduardonunesp/2536f11bdf84ecb0f5be9a2dec6b65c1 to your computer and use it in GitHub Desktop.
Save eduardonunesp/2536f11bdf84ecb0f5be9a2dec6b65c1 to your computer and use it in GitHub Desktop.
let mut f = BufWrtier::new(File::create(filename).expect("Could not create file"));
let text = include_bytes!("filename.txt");
f.write(text);
let text2 = include_str!("filename.txt");
f.write(text2.as_bytes());
let data = vec![b"this will be represented as a vector of bytes"];
f.write(&data[..]);
use std::io::{BufReader, BufRead, BufWriter, Write};
use std::fs::File;
use std::prelude::*;
// Buffered file reading
let mut f = BufReader::new(File::open("filename.txt").expect("Could not open file"));
for line in f.lines() {
match file_line {
Err(e) => println!("Error: {}", e);
Ok(line) => {
// ...
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment