最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

使用fs.read时,没有返回值到console.log中

运维笔记admin10浏览0评论

使用fs.read时,没有返回值到console.log中

使用fs.read时,没有返回值到console.log中

我需要帮助阅读文本文件information.txt,并使用console.log显示值。

这是代码:

fs.readFileSync("information.txt", "utf-8", function (err, data) {                                                                                         
  if (err) {
    throw err;
  }

  var content = data;
  console.log(content);
});
回答如下:

您的代码中有一些错误,这是一个工作版本:

var fs = require('fs');

var content = fs.readFileSync("themes", "utf-8");
console.log(content);
发布评论

评论列表(0)

  1. 暂无评论