简体   繁体   English

读取 Node.js 中的文件

[英]Reading file in Node.js

How to read the data of a file(say, read.txt) without getting the buffered Data?如何在不获取缓冲数据的情况下读取文件(比如 read.txt)的数据? I mean I want to get the content of the file directly without getting the buffer data?我的意思是我想直接获取文件的内容而不获取缓冲区数据? and hoe to delete the folder in Node.js?并锄头删除 Node.js 中的文件夹?

// Try this //

    fs = require('fs')
    fs.readFile('/read.txt', 'utf8', function (err,data) {
      if (err) {
        return console.log(err);
      }
      console.log(data);
    });
    
    try {
    fs.rmdirSync(dir, { recursive: true });

    console.log(`${dir} is deleted!`);
    }catch (err) {
    console.error(`Error while deleting ${dir}.`);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM