File input/output: Difference between revisions

→‎Rust: Use `std::fs::{read, write}` to make the solution simpler
m (Removed spaces around Uxntal code.)
imported>Collin
(→‎Rust: Use `std::fs::{read, write}` to make the solution simpler)
Line 3,531:
 
=={{header|Rust}}==
<syntaxhighlight lang="rust">usefn std::fs::File;main() {
let contents = std::fs::read("input.txt").expect("error reading input.txt");
use std::io::{Read, Write};
std::fs::write("output.txt", contents).expect("error writing output.txt");
 
fn main() {
let mut file = File::open("input.txt").unwrap();
let mut data = Vec::new();
file.read_to_end(&mut data).unwrap();
let mut file = File::create("output.txt").unwrap();
file.write_all(&data).unwrap();
}
</syntaxhighlight>
Anonymous user