fs.copyFileSync("file1.txt", "file2.txt");抛出错误

发布于 2025-01-14 03:08:49 字数 877 浏览 2 评论 0 原文

const fs = require('fs'); fs.copyFileSync("file1.txt", "file2.txt");

//当我尝试在 hyper 上运行此代码时,会出现此错误

Error: ENOENT: no such file or directory, copyfile 'file1.txt' -> 'file2.txt' ←[Object.copyFileSync 处的 90m(节点:fs:2802:3)←[Object 处的 39m。 (C:\Users\ahmad\Desktop\intro-to-node\index.js:2:4) ←[90m at Module._compile (node:internal/modules/cjs/loader:1103:14)←[39m ← [90m 在 Object.Module._extensions..js (节点:internal/modules/cjs/loader:1155:10)←[39m ←[90m 在 Module.load (节点:internal/modules/cjs/loader:981:32)←[39m ←[90m 在 Function.Module._load (节点:internal/modules/cjs/loader:822:12)← [39m ←[90m 在 Function.executeUserEntryPoint [作为 runMain] (节点:internal/modules/run_main:77:12)←[39m ←[90m 位于节点:internal/main/run_main_module:17:47←[39m { errno: ←[33m-4058←[39m, 系统调用: ←[ 32m'复制文件'←[39m,代码:←[32m'ENOENT'←[39m,路径: ←[32m'文件1.txt'←[39m,目标:←[32m'文件2.txt'←[39m }

const fs = require ('fs');
fs.copyFileSync("file1.txt", "file2.txt");

//when i try to run this code on hyper it gives this error

Error: ENOENT: no such file or directory, copyfile 'file1.txt' -> 'file2.txt' ←[90m at Object.copyFileSync (node:fs:2802:3)←[39m at Object. (C:\Users\ahmad\Desktop\intro-to-node\index.js:2:4) ←[90m at Module._compile (node:internal/modules/cjs/loader:1103:14)←[39m ←[90m at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)←[39m ←[90m at Module.load (node:internal/modules/cjs/loader:981:32)←[39m ←[90m at Function.Module._load (node:internal/modules/cjs/loader:822:12)←[39m ←[90m at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)←[39m ←[90m at node:internal/main/run_main_module:17:47←[39m { errno: ←[33m-4058←[39m, syscall: ←[32m'copyfile'←[39m, code: ←[32m'ENOENT'←[39m, path: ←[32m'file1.txt'←[39m, dest: ←[32m'file2.txt'←[39m }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事未完 2025-01-21 03:08:49

此错误告诉您 file1.txt 不存在或不可读。

检查 file1.txt 是否存在。检查您的 file1.txt 是否与您的 node.js 脚本位于同一目录中,如果不在 file1.txt 之前添加路径。

This error tell you that file1.txt does not exists or is not readable.

Check if file1.txt exists. Check if your file1.txt is in the same directory than your node.js script, if not add a path before file1.txt.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文