- 檔案系統模組
- PhantomJS - 屬性
- PhantomJS - 方法
- 系統模組
- PhantomJS - 屬性
- 網路伺服器模組
- PhantomJS - 屬性
- PhantomJS - 方法
- 其他
- 命令列介面
- PhantomJS - 螢幕截圖
- PhantomJS - 頁面自動化
- PhantomJS - 網路監控
- PhantomJS - 測試
- PhantomJS - REPL
- PhantomJS - 示例
- PhantomJS 實用資源
- PhantomJS - 快速指南
- PhantomJS - 實用資源
- PhantomJS - 討論
PhantomJS - 寫入
此方法包含三個引數:源、內容和字串/物件。
源 - 是將內容寫入的檔案。
內容 - 此引數是要寫入檔案的內容。
字串/物件 - 此引數具有模式和字元集。
模式 - 開啟模式。由“r”、“w”、“a/+”、“b”字元組成的一個字串。
字元集 - 一個不區分大小寫、不區分大小寫的 IANA 字元集名稱。
語法
其語法如下-
fs.write(path, content, 'w');
示例
以下示例演示了write 方法的工作原理。
命令 - phantomjs write.js writemode.txt
var fs = require('fs');
var system = require('system');
var path = system.args[1];
var md = fs.touch(path);
console.log("file is present : "+fs.isFile(path));
var n = fs.write(path, 'Hello world', 'w');
console.log("Content present in " +path + " are :");
console.log(fs.read(path));
phantom.exit();
上述程式會生成以下輸出。
file is present : true Content present in writemode.txt are : Hello world
phantomjs_file_system_module_methods.htm
廣告