- 檔案系統模組
- PhantomJS - 屬性
- PhantomJS - 方法
- 系統模組
- PhantomJS - 屬性
- 網路伺服器模組
- PhantomJS - 屬性
- PhantomJS - 方法
- 雜項
- 命令列介面
- PhantomJS - 螢幕截圖
- PhantomJS - 頁面自動化
- PhantomJS - 網路監控
- PhantomJS - 測試
- PhantomJS - REPL
- PhantomJS - 例項
- PhantomJS 有用資源
- PhantomJS - 快速指南
- PhantomJS - 有用資源
- PhantomJS - 討論
PhantomJS - 開啟
Open 方法採用兩個引數,分別是——檔案路徑和物件引數。
物件引數可以包含 -
模式 - 開啟模式。由“r”、“w”、“a/+”、“b”字元組成的字串。
字元集 - IANA、不區分大小寫的字元集名稱。
流物件由 fs.open 方法返回。開啟後必須關閉流。當呼叫期間發生錯誤時,它將引發“Unable to open file PATH”錯誤並掛起執行。
語法
其語法如下 -
fs.open('filepath', 'r or w or a/+ or b');
示例
我們舉一個例子來了解 open 方法如何工作。
var fs = require('fs');
var file = fs.open('openmode.txt', 'r');
console.log(file);
file.close();
以上程式生成以下輸出。
File(name = "")
phantomjs_file_system_module_methods.htm
廣告