Maison > Questions et réponses > le corps du texte
var fs = require('fs');
var path = 'files',name = 'ANG-100';
for (var i=0;i<20;i++ ) {
var number = 2070 + i;
var pathStr = path + '/' + name + number.toString();
fs.mkdirSync(pathStr,0777);
var newPathStr = pathStr + '/' + name + number.toString() + '.txt';
fs.mkdirSync(newPathStr,0777);
}
怎样设置创建的文件为txt文件?
PHP中文网2017-04-17 14:41:21
var fs = require('fs');
fs.writeFile(path + "test.txt", "hello world!", function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});