![](/img/trans.png)
[英]Create and edit file javascript with “file_put_contents”?
[英]Is there equivalent for file_put_contents in javascript?
请问,javascript中file_put_contents的等价物是什么?
先感谢您。
在JavaScript? 没有。
在NodeJS? 是的,它被称为writeFile
。 这是文档中的示例:
fs.writeFile('message.txt', 'Hello Node', function (err) { if (err) throw err; console.log('It\\'s saved!'); });
如果你不想覆盖文件的内容而是附加到它,只是添加到上面的回复
var fs = require('fs'); // don't forget to require in the header or it won't work
fs.writeFile(
"foo.txt", // file
"bar", // string
{
encoding: "utf8",
flag: "a" // flag that specifies that it will append stuff
},
function(){ console.log("done!") }
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.