PhantomJS - open



The Open method takes two parameters, which are – file path and the object parameter.

The object parameter can contain −

  • Mode − Open Mode. A string made of ‘r’, ‘w’, ‘a/+’, ‘b’ characters.

  • Charset − An IANA, case insensitive, charset name.

Stream objects are returned from the fs.open method. The stream has to be closed once open. When errors occur during a call, it will throw an ‘Unable to open file PATH’ error and hang execution.

Syntax

Its syntax is as follows −

fs.open('filepath', 'r or w or a/+ or b'); 

Example

Let us take an example to understand how the open method works.

var fs = require('fs'); 
var file = fs.open('openmode.txt', 'r'); 
console.log(file); 
file.close();

The above program generates the following output.

File(name = "")
phantomjs_file_system_module_methods.htm
Advertisements