Create a file called "output.txt", and place in it the contents of the file "input.txt" via an intermediate variable.
Haskell
Note: This doesn't keep the file in memory. Buffering is provided by lazy evaluation.
main = readFile "input.txt" >>= writeFile "output.txt"
Python
i = open("input.txt", "r") o = open("output.txt", "w+") o.write(i.read())
Rust
Note: The program will panic with any sort of error.
use std::fs::File; use std::io::{Read, Write}; 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(); }
JavaScript
const fs = require('fs'); const content = fs.readFileSync('input.txt'); fs.writeFileSync('output.txt', content);