Description of Fs.readfile method used in Node.js _node.js

Source: Internet
Author: User
Tags readfile

Method Description:

Read the contents of the file in an asynchronous fashion.

Without the top content encoding, the output will be in Buffer format, such as: <buffer to 33>

Grammar:

Copy Code code as follows:

Fs.readfile (filename, [encoding], [Callback (Err,data)])

Because this method belongs to the FS module, it is necessary to introduce FS module (VAR fs= require ("FS") before use.

Receive parameters:

FileName File path

Options option object, which contains encoding, encoding format, which is optional.

Callback callback, passing 2 parameter exception err and file content data

Example:

Copy Code code as follows:

var fs = require (' FS ');
Fs.readfile (' Content.txt ', ' utf-8 ', function (err,data) {
if (err) {
Console.log (ERR);
}else{
Console.log (data);
}
})

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.