使用Node Webkit编写文本文件 [英] Writing text files with node webkit

查看:109
本文介绍了使用Node Webkit编写文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做一个相当简单的事情:将一个文本文件和一个在文本输入字段中输入的数据写入文件...

I'm trying to do something rather simple: write a text file with data entered in a text input field to a file...

var data = document.getElementById("fileContent").value;
fs.writeFileSync("test.txt", data);

例如,如果我输入

Write this to file 123 123

我最终将其保存在文件中...

I end up with this in the file...

Write this to

如果我将字符串硬编码到应用程序中,它将正确写入.

If I hard code a string into the application, it writes correctly.

fs.writeFileSync("test.txt", "this is a hard coded string");

我尝试使用带有和不带有编码参数集的writeFileSync.我试过了createWriteStream,是否对参数集进行了编码.我试过了fileOpen,fs.writeSync和fs.close.我什至尝试将日期转换为Buffer对象并编写.在每种情况下,我都得到完全相同的结果.

I tried using writeFileSync with and without the encoding parameter set. I've tried createWriteStream with and without encoding the parameter set. I've tried fileOpen, fs.writeSync, and fs.close. I even tried converting the date to a Buffer object and writing that. In every case, I got the exact same results.

编码也很奇怪. Notepad ++表示编码为"UCS2-LE w/o BOM",我希望它的编码为UTF-8,因为我一直在设置编码参数.

The encoding is also strange. Notepad++ indicates that the encoding is "UCS2-LE w/o BOM" I'd expect it to be UTF-8, as I'v been setting the encoding parameter to that.

有什么想法吗?

推荐答案

  1. 这是Node-Webkit-v0.9的错误.*
  2. 如果使用Node-Webkit-v.8.*或更低版本,则可以.

这篇关于使用Node Webkit编写文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆