
nodejs如何读取/修改文件,下面web建站小编给大家详细介绍一下具体代码!
const fs = require('fs')
const path = require('path')
fs.readFile(path.join(__dirname, 'files', 'file1'), (err, buf) => {
if (err) throw err
console.log(buf.toString())
})
修改文件
const fs = require('fs')
const path = require('path')
fs.writeFile(path.join(__dirname, 'files', 'file3'), '欢迎光临', (err) => {
if (err) throw err
console.log('写入完成')
// 在文件末尾追加
fs.appendFile(path.join(__dirname, 'files', 'file3'), '\n\n男宾三位', (err) => {
if (err) throw err
console.log('追加完成')
// 修改文件名称
fs.rename(path.join(__dirname, 'files', 'file3'), path.join(__dirname, 'files', 'file3-rename'), (err) => {
if (err) throw err
console.log('改名完成')
})
})
})
上面是“nodejs如何读取/修改文件”的全面内容,想了解更多关于 nodejs 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_3148.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

网站建设过程中如何布局关键词有利于SEO优化?
Dualite:AI前端开发平台,无需手动编写大量代码即可完成应用构建
SF轻小说官网入口,提供在线漫画浏览、在线小说阅读、动漫综合社区等服务
头条站长平台PC端入口,一个专门为网站管理员设计的工具集
讯飞星火认知大模型:大讯飞推出的一款新一代认知智能大模型
智谱清言:一款由智谱AI推出的超强AI助手,找到属于自己的“超级大脑”