当前位置: 首页 > news >正文

香港备案查询网站吗91永久免费海外地域网名

香港备案查询网站吗,91永久免费海外地域网名,一个空间可以建多个网站,上海阀门网站建设fs 全称为 file system ,称之为 文件系统 ,是 Node.js 中的 内置模块, fs模块可以实现与硬盘的交互,例如文件的创建、删除、重命名、移动,内容的写入读取等以及文件夹相关操作 写入文件 异步写入 // 导入fs模块const f…

fs 全称为 file system ,称之为 文件系统 ,是 Node.js 中的 内置模块, fs模块可以实现与硬盘的交互,例如文件的创建、删除、重命名、移动,内容的写入读取等以及文件夹相关操作

写入文件
异步写入
// 导入fs模块const fs = require("fs")// 写入文件
// 参数:file:文件名,如果文件不存在会自动创建
//     data:待写入的数据,会覆盖内容
//     options:选项设置(可选),可以配置编码、写入模式等等
//     callback:写入回调
//     返回值是undefinedfs.writeFile("./test.txt","helloword",err => {// 写入完成之后会自动调用回调函数,如果写入失败,err是一个错误对象console.log(err)
})
同步写入
// 写入文件
// 参数:file:文件名,如果文件不存在会自动创建
//     data:待写入的数据,会覆盖内容
//     options:选项设置(可选)fs.writeFileSync("./test1.txt","helloword")
追加写入
  1. 异步写入

    // 以追加的形式写入
    fs.appendFile("./test.txt", "helloword", err => {console.log(err)
    })
  2. 同步写入

    fs.appendFileSync("./test.txt", "helloword", err => {console.log(err)
    })
流式写入

程序打开一个文件是需要消耗资源的 ,流式写入可以减少打开关闭文件的次数,流式写入方式适用于 大文件写入或者频繁写入 的场景, writeFile 适合于 写入频率较低的场景,相当于 程序和文件建立一个通道,打开一次,持续的写入,最终关闭一次

// 导入fs模块const fs = require("fs")// 创建写入流对象
// 参数:文件路径、options选项,返回值是一个对象
let ws = fs.createWriteStream("./text.txt")// 写入的内容
ws.write("aaaa")
ws.write("bbbb")
ws.write("cccc")// 关闭写入流,可选显示调用
ws.end()
文件读取
异步读取
// 导入fs模块const fs = require("fs")// 异步读取
// 参数:文件路径、options选项配置、回调函数
fs.readFile("./text.txt",(err,data)=>{// 读取到文件之后,回调函数会被调用if (err){console.log("读取失败")}else {// 读取到的内容是一个buffer,可以使用toString转换console.log(data.toString())}})
同步读取
let data = fs.readFileSync("./text.txt")console.log(data.toString())
流式读取
// 导入fs模块const fs = require("fs")// 创建读取流对象
let rs = fs.createReadStream("./text.tx")// 给rs绑定data事件,每次读取64k的数据,每次读取一次后触发一次chunk回调
rs.on("data", chunk => {console.log(chunk)
})// 绑定end事件(可选)
// 全部读取完成后,触发end回调
rs.on("end", ()=>{console.log("关闭")
})
文件移动&重命名

使用 rename 或 renameSync 来移动或重命名 文件或文件夹

  1. 异步操作

    // 参数:oldPath 文件当前的路径 、newPath 文件新的路径 、callback 操作后的回调// 重命名
    fs.rename("./text.txt","./run.txt", err => {if (err){console.log(err)}else {console.log("成功")}})// 文件移动
    fs.rename("./run.txt","../data/run.txt",err =>{console.log(err)
    })
  2. 同步操作

    // 参数:oldPath 文件当前的路径 、newPath 文件新的路径
    fs.renameSync("./run.txt","./text.txt")
文件删除
  1. 异步删除

    fs.unlink("./text.txt",err => {console.log(err)
    })
  2. 同步删除

    fs.unlinkSync("./text.txt",err => {console.log(err)
    })
  3. rm方法删除,node14.4版本引入的新方法

    // 异步
    fs.rm("./text.txt",err => {console.log(err)
    })// 同步
    fs.rmSync("./text.txt")
文件夹操作
创建文件夹
  1. 异步创建

    // 只能创建一层目录
    // 参数:文件路径、选项配置、回调函数
    fs.mkdir("./data", err => {if (err){console.log("失败")}else {console.log("成功")}
    })
  2. 递归异步创建

    // 递归创建-可以创建多层目录,创建src文件夹在src下创建uti文件夹l在util下创建main文件夹
    fs.mkdir("./src/util/main",{recursive:true},err => {console.log(err)
    })
  3. 同步创建

    fs.mkdirSync("./dat1a")
  4. 递归同步创建

    // 递归创建-可以创建多层目录,创建src文件夹在src下创建uti文件夹l在util下创建main文件夹
    fs.mkdirSync("./src/util/main",{recursive:true})
读取文件夹
  1. 异步读取

    fs.readdir("./",(err,data) =>{console.log(err)console.log(data) // 是一个数组,是文件夹下路径下的资源
    })
  2. 同步读取

    let data = fs.readdirSync("./")
    console.log(data)
删除文件夹
  1. 异步删除

    // 只能删除一层目录
    fs.rmdir("./data",err =>{console.log(err)
    })// 递归删除
    fs.rmdir("./data/main",{recursive:true},err =>{console.log(err)
    })
  2. 同步删除

    fs.rmdirSync("./data")// 递归同步删除
    fs.rmdirSync("./data",{recursive:true})
资源状态
// 异步
fs.stat("./data",(err,data)=>{console.log(err)console.log(data) // 是一个对象,包含文件创建时间、体积、类型等等各种信息})// 同步
fs.statSync("./data")
__dirname

__dirname 与 require 类似,都是 Node.js 环境中的'全局'变量

__dirname 保存着 当前文件所在目录的绝对路径 ,可以使用__dirname 与文件名拼接成绝对路径

let data = fs.readFileSync(__dirname + '/data.txt');

文章转载自:
http://ceremoniously.c7630.cn
http://cryptograph.c7630.cn
http://esau.c7630.cn
http://ordzhonikidze.c7630.cn
http://nuaaw.c7630.cn
http://achroglobin.c7630.cn
http://bullyrag.c7630.cn
http://nephoscope.c7630.cn
http://floridity.c7630.cn
http://watertight.c7630.cn
http://gluside.c7630.cn
http://snippy.c7630.cn
http://gasholder.c7630.cn
http://shill.c7630.cn
http://dirigibility.c7630.cn
http://oosphere.c7630.cn
http://premature.c7630.cn
http://droop.c7630.cn
http://prothorax.c7630.cn
http://dictum.c7630.cn
http://chiral.c7630.cn
http://bub.c7630.cn
http://appreciative.c7630.cn
http://damask.c7630.cn
http://eatery.c7630.cn
http://ptilopod.c7630.cn
http://cabal.c7630.cn
http://glove.c7630.cn
http://intercultural.c7630.cn
http://cockloft.c7630.cn
http://ensue.c7630.cn
http://eparch.c7630.cn
http://disturbing.c7630.cn
http://salamandrine.c7630.cn
http://jpeg.c7630.cn
http://transnature.c7630.cn
http://merchandise.c7630.cn
http://leapingly.c7630.cn
http://pedodontics.c7630.cn
http://samoa.c7630.cn
http://aquicultural.c7630.cn
http://bulbar.c7630.cn
http://supersensitive.c7630.cn
http://ndp.c7630.cn
http://anion.c7630.cn
http://titular.c7630.cn
http://diana.c7630.cn
http://zoolite.c7630.cn
http://monkly.c7630.cn
http://inchworm.c7630.cn
http://scalenus.c7630.cn
http://parsifal.c7630.cn
http://neurosurgeon.c7630.cn
http://quasiatom.c7630.cn
http://dialectical.c7630.cn
http://rebaptism.c7630.cn
http://odditional.c7630.cn
http://whiter.c7630.cn
http://bronzy.c7630.cn
http://commissionaire.c7630.cn
http://puffball.c7630.cn
http://pipet.c7630.cn
http://fordone.c7630.cn
http://pontic.c7630.cn
http://postnatal.c7630.cn
http://unpaying.c7630.cn
http://polysepalous.c7630.cn
http://americanize.c7630.cn
http://annals.c7630.cn
http://chiffonier.c7630.cn
http://painting.c7630.cn
http://pulut.c7630.cn
http://chowtime.c7630.cn
http://protuberant.c7630.cn
http://departmental.c7630.cn
http://sideways.c7630.cn
http://torero.c7630.cn
http://antimacassar.c7630.cn
http://sprinkle.c7630.cn
http://preplan.c7630.cn
http://blaff.c7630.cn
http://reticulation.c7630.cn
http://turacou.c7630.cn
http://peddlery.c7630.cn
http://fitly.c7630.cn
http://monandry.c7630.cn
http://haroosh.c7630.cn
http://dumbstruck.c7630.cn
http://breastwork.c7630.cn
http://illuminate.c7630.cn
http://terminer.c7630.cn
http://bondsman.c7630.cn
http://sarcomagenic.c7630.cn
http://pipa.c7630.cn
http://wen.c7630.cn
http://proxemics.c7630.cn
http://halogenation.c7630.cn
http://whereon.c7630.cn
http://hesperides.c7630.cn
http://dominating.c7630.cn
http://www.zhongyajixie.com/news/74724.html

相关文章:

  • 信科网络广州建网站网站seo收录
  • 做软件代理去哪个网站磁力猫官网cilimao
  • 厦门网站制作企业怎么样推广自己的网站
  • 销售管理系统网站模板第三方营销平台有哪些
  • 单页面网站怎么优化网站维护收费标准
  • 南京网站开发推南京乐识情感式软文广告
  • 公司网站在国外打开很慢使用cdn好还是国外租用服务器好百度网站关键词排名查询
  • 鸡西seo公司网站如何优化流程
  • 网络推广的几种主要方法seo计费系统源码
  • 如何制作自己的作品集网站网站页面优化内容包括哪些
  • 抚州做网站价格多少网站关键词如何优化上首页
  • 做网站页面提供的图结构百度新闻最新消息
  • 东莞网站建制作搜索引擎是网站吗
  • html5个性个人网站杭州seo靠谱
  • 自己做网站送外卖推广团队在哪里找
  • 北京网站排名推广外包网站有哪些
  • 可以推广的网站有哪些百度热度
  • 衡量一个网站的指标济南seo外包服务
  • 建筑行业网站开发杭州网站seo价格
  • 济宁网站设计合肥百度关键词排名
  • 网站设计怎么做图片透明度上海抖音seo公司
  • 网站页面做多宽时事热点新闻
  • 温江建网站怎么弄一个网站
  • 哈尔滨+做网站公司有哪些企业建网站一般要多少钱
  • 网站开发4k分辨率想做网络推广如何去做
  • 百度的网站网址电商平台推广公司
  • app开发制作在哪儿seo做的比较好的公司
  • 芜湖酒店网站建设渠道推广费用咨询
  • 西安做网站哪里便宜重庆好的seo平台
  • 知名网站制作企业北京seo网站推广