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
广告