Read file operation with NODEJS implementation

Source: Internet
Author: User
Tags readfile

//if not global, you have to introduce FS membersConstFS = require ("FS");//a Fs.readfile method is provided in the FS core module to read the files in the specified directory//Fs.resdfile of three parameters//1, read the path to the file//2. Read the encoding format of the file//3, when the file reads complete, call this callback callback function to read the result of the file//first argument text Error object The second argument is the result of a successful read//fs.readfile ('./http/111.txt ', ' utf-8 ', function (error,data) {//Console.log (Error); //If err is null it means that the read was successful and there was no error//console.log (data);//If you do not give the second parameter [read file encoding format] It will be output in beffer format// });Fs.readfile ("./http/111.txt","Utf-8", function (error, data) {//Console.log (Error); //If err is null it means that the read was successful and there was no error//console.log (data);//If you do not give the second parameter [read file encoding format] It will be output in beffer format//use error to determine if the file was read successfully  if(Error)returnConsole.log ("failed to read file, content is"+error.message); Console.log ("read file successfully, content is"+( data);});

Read file operation with NODEJS implementation

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.