2016-04-21 72 views
3

如何查找給定文本文件的字符編碼?nodejs獲取文件字符編碼

var inputFile = "filename.txt"; 
var file = fs.readFileSync(inputFile); 
var data = new Buffer(file, "ascii"); 
var fileEncoding = some_clever_function(file); 
if (fileEncoding !== "utf8") { 
    // do something 
} 

感謝

回答