search
尋找貓咪~QQ 地點 桃園市桃園區 Taoyuan , Taoyuan

[Node.js]讀取檔案

Node.js檔案操作可以透過fs這個module處理

讀取檔案

var fs = require("fs");
var filename = "test.html";
var encode = "utf8";

fs.readFile(filename, encode, function(error, data){
        console.log(data);
});

寫入檔案

//Write
fs.writeFile('message.txt', 'Hello Node', function (err) {
        if (err) throw err;
        console.log('It\'s saved!');
});

//Append
fs.appendFile('message.txt', 'data to append', function (err) {
        if (err) throw err;
        console.log('The "data to append" was appended to file!');
});
Categories: Node.js



熱門推薦

本文由 blogjohnsonluorg 提供 原文連結

寵物協尋 相信 終究能找到回家的路
寫了7763篇文章,獲得2次喜歡
留言回覆
回覆
精彩推薦