[英]Node.js: strange symbol “^@” using fs.writeFile
I've built and run Node.js on emmbed linux-os with MIPS 24K Little Endian CPU. 我已经在带有MIPS 24K Little Endian CPU的嵌入式linux-os上构建并运行Node.js。 Node.js version is v0.12.0.
Node.js版本是v0.12.0。 Everything works fine except when I use fs.writeFile, example code:
一切正常,除非我使用fs.writeFile示例代码:
var fs = require('fs');
fs.writeFile("/tmp/test.txt","hello world!",'utf-8', function(err){
if(err){
return console.log(err);
}
console.log("saved");
});
Using vim to check this test.txt, the content is: 使用vim检查此test.txt,内容为:
^@hello world!
Obviously, there's an undesireable symbol "^@" in the beginning of the written file. 显然,在书面文件的开头有一个不受欢迎的符号“ ^ @”。
So how does this problem happen and how to solve it? 那么,这个问题如何发生以及如何解决呢?
First thing to do is to try retyping the hello world
string, it may be that you've somehow inserted a NUL
, or CTRL-@ character into it before the h
. 首先要做的是尝试重新键入
hello world
字符串,这可能是您已经在h
之前以某种方式在其中插入了NUL
或CTRL- @字符。 ECMAScript actually allows this, as NUL
is not one of the characters forbidden to appear in a string literal. ECMAScript实际上允许这样做,因为
NUL
并不是禁止在字符串文字中出现的字符之一。
You could check this before-hand by doing a hex dump of the source file to see what actual characters are in there. 您可以通过对源文件进行十六进制转储来进行检查,以查看其中实际存在的字符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.