Skip to content

Instantly share code, notes, and snippets.

@tonyc726
Created May 17, 2014 09:58
Show Gist options
  • Save tonyc726/650f4507fd3aaf9bf872 to your computer and use it in GitHub Desktop.
Save tonyc726/650f4507fd3aaf9bf872 to your computer and use it in GitHub Desktop.
nodeJS小记
var fs = require('fs');
var iconv = require('iconv-lite');
fs.readFile('./a_uft8.md', function(err, data) {
if (err) {
console.error(err);
} else {
var str = iconv.decode(data, 'utf-8');
var str2 = iconv.encode(str, 'gbk')
var str3 = iconv.decode(str2, 'gbk')
console.log(data)
fs.writeFile('./b_gbk.md', str2, null, function (err) {
if (err) throw err;
console.log('It\'s saved!');
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment