File input/output: Difference between revisions

Content added Content deleted
m (Removed spaces around Uxntal code.)
imported>Collin
(→‎Rust: Use `std::fs::{read, write}` to make the solution simpler)
Line 3,531: Line 3,531:


=={{header|Rust}}==
=={{header|Rust}}==
<syntaxhighlight lang="rust">use std::fs::File;
<syntaxhighlight lang="rust">fn 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>
</syntaxhighlight>