- PhantomJS Tutorial
- PhantomJS - Home
- PhantomJS - Overview
- PhantomJS - Environment Setup
- PhantomJS - Object
- PhantomJS - Methods
- WebPage Module
- PhantomJS - Properties
- PhantomJS - Methods
- PhantomJS - Events/Callbacks
- PhantomJS - Child Process Module
- File System Module
- PhantomJS - Properties
- PhantomJS - Methods
- System Module
- PhantomJS - Properties
- Web Server Module
- PhantomJS - Properties
- PhantomJS - Methods
- Miscellaneous
- Command Line Interface
- PhantomJS - Screen Capture
- PhantomJS - Page Automation
- PhantomJS - Network Monitoring
- PhantomJS - Testing
- PhantomJS - REPL
- PhantomJS - Examples
- PhantomJS Useful Resources
- PhantomJS - Quick Guide
- PhantomJS - Useful Resources
- PhantomJS - Discussion
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