- 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 - write
This method takes three parameters: Source, Content, and String/Object.
Source − It is the file, where the content has to be written.
Content − This parameter is the content that needs to be written to the file.
String/Object − This parameter has the mode and charset.
Mode − Open mode. A string made of ‘r’, ‘w’, ‘a/+’, ‘b’ characters.
Charset − An IANA, case insensitive, charset name.
Syntax
Its syntax is as follows −
fs.write(path, content, 'w');
Example
The following example shows how the write method works.
Command − phantomjs write.js writemode.txt
var fs = require('fs'); var system = require('system'); var path = system.args[1]; var md = fs.touch(path); console.log("file is present : "+fs.isFile(path)); var n = fs.write(path, 'Hello world', 'w'); console.log("Content present in " +path + " are :"); console.log(fs.read(path)); phantom.exit();
The above program generates the following output.
file is present : true Content present in writemode.txt are : Hello world
phantomjs_file_system_module_methods.htm
Advertisements