fs.writeFile(filename, data[, options], callback)
If the file exists , The content that is written will override the contents of the old file
The parameters are described below :
path - File path .
data - The data to write to the file , It can be String( character string ) or Buffer( flow ) object .
options - The parameter is an object , contain {encoding, mode, flag}. The default encoding is utf8, The model is 0666 ,flag
by 'w'
callback - Callback function , The callback function contains only error message parameters (err), Return on write failure .
var fs = require('fs'); console.log(' Ready to write to file '); fs.writeFile('input.txt',
' I'm new writing ', function (err) { if (err) console.error(err);
console.log(' Data written to data '); console.log('-------------------'); });
console.log(' Read written data '); fs.readFile('input.txt', function (err, data) { if
(err) console.error(err); console.log(' Read file data asynchronously :' + data.toString()); })
Technology