suchen

Heim  >  Fragen und Antworten  >  Hauptteil

node.js - nodejs怎样新建txt文件?

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文件?

怪我咯怪我咯2778 Tage vor600

Antworte allen(2)Ich werde antworten

  • PHP中文网

    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!");
    });
    

    Antwort
    0
  • 怪我咯

    怪我咯2017-04-17 14:41:21

    如何递归创建多级文件夹?

    Antwort
    0
  • StornierenAntwort