node.js - 使用 Node js 读取文件时出错
问题描述
我无法使用我在互联网上找到的此代码读取文件...
var express = require('express');
var app = express();
var fs = require('fs');
var port = 8080;
app.get('/', function(req, res) {
fs.readFile('./queries/anagconti_clienti_giorni.txt', 'utf8', function(err, data) {
if (err) {
res.send(err);
} else {
res.send(data);
}
});
});
var server = app.listen(port, function() {
console.log("Started on http://localhost:" + port);
});
它给我的错误是:
{
“errno”:-4058,
“代码”:“ENOENT”,
“系统调用”:“打开”,
“路径”:“C:\Users\AlessandroGolin\Desktop\Mia\Visual_Studio\server_link\queries\anagconti_clienti_giorni.txt
” }
什么可能导致此错误?
解决方案
请交叉检查“./queries/anagconti_clienti_giorni.txt”文件的路径或权限。如果文件不存在,则在上述代码文件所在的同一级别创建“查询”文件夹。
推荐阅读
- data-structures - 如何将flutter项目从windows导入linux?
- android - 如何在 Firebase 控制台中读取事件 SELECT_CONTENT 的详细信息
- ios - 滚动时是否可以禁用 UITableview 多个“cellForRowAt”方法调用?
- ios - 如何更新 WDA WebDriverAgentRunner 产品构建版本?
- x86 - 为什么编译器将数据放在 PE 和 ELF 文件的 .text(code) 部分,CPU 如何区分数据和代码?
- blueprism - Blue Prism - 在一个过程中使用多个应用程序 - 保留相关数据
- python - 从周围的边界框中提取车牌平行四边形?
- algorithm - 如何遍历一棵树以找到最小值
- javascript - style.styleSheet.cssText 在 IE 9 上不起作用
- azure-active-directory - 如何将restapi响应中的列映射到数据库表列?