Copy File
NodeJS
Hard
4 views
Problem Description
Copy a source file to destination and print COPIED.
Input Format
stdin: two paths (src dest).
Output Format
Print COPIED or FAIL.
Constraints
Use readFileSync/writeFileSync.
Official Solution
const fs = require('fs');
const s = fs.readFileSync(0, 'utf8').trim().split(/\\s+/);
if (s.length < 2) process.exit(0);
const src = s[0];
const dest = s[1];
try {
const buf = fs.readFileSync(src);
fs.writeFileSync(dest, buf);
console.log('COPIED');
} catch (e) {
console.log('FAIL');
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!