PhantomJS - 讀取



此方法讀取指定檔案中存在的資料。

語法

其語法如下 −

var fs = require('fs'); 
fs.read(path); 

示例

我們來看一個示例,瞭解 **read** 方法如何工作。

命令 − phantomjs read.js test.txt

var fs = require('fs'); 
var system = require('system'); 
var path = system.args[1]; 

console.log(fs.read(path)); 
phantom.exit();

Test.txt 檔案

I am Testing Phantomjs

以上程式會生成以下 **輸出**。

I am Testing Phantomjs
phantomjs_file_system_module_methods.htm
廣告
© . All rights reserved.