1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| const fs = require('fs'); const iconv = require('iconv-lite');
const inputFile = 'input.md'; const outputFile = 'output.md'; const inputEncoding = 'GB18030'; const outputEncoding = 'utf-8';
fs.readFile(inputFile, (err, data) => { if (err) { console.error('读取文件出错:', err); return; }
const content = iconv.decode(data, inputEncoding);
const modifiedContent = content.toUpperCase();
const outputData = iconv.encode(modifiedContent, outputEncoding);
fs.writeFile(outputFile, outputData, (err) => { if (err) { console.error('保存文件出错:', err); return; } console.log('文件保存成功!'); }); });
|