NodeJS-使用ANSI编码保存TXT文件 [英] NodeJS - Saving TXT file with ANSI encoding
本文介绍了NodeJS-使用ANSI编码保存TXT文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Linux PC中创建了一个简单的应用程序,该应用程序使用 fs
NodeJS命令生成TXT文件.但是我需要使用外部Window应用程序读取这些文件.所以我需要那些文件以ANSI编码.我安装了Wine,现在,我用记事本打开文件,然后再次保存以转换编码.有什么方法可以直接从NodeJS生成具有ANSI编码的TXT文件吗?
I created in my Linux PC a simple app that generates TXT files using fs
NodeJS command. But I need read those files with an external Window app. So I need those files in ANSI encode. I installed Wine and for now, I open the file with notepad and save it again to convert the codification.
There is any way to generate the TXT files with ANSI encoding from NodeJS directly?
推荐答案
我这样解决了我的问题:
I solved my question like this:
let txtContent = '' // string with content to save as file
const buffer = Buffer.from(txtContent, 'latin1')
fs.writeFile('files/file_name.txt')
这篇关于NodeJS-使用ANSI编码保存TXT文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文