From 9c8408fe190ee4555d981e271d3bbcf27fc9178e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E9=9D=92=E9=9D=92?= <2910939733@qq.com> Date: Mon, 28 Feb 2022 16:49:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../a.txt" | 1 + .../b.txt" | 1 + .../demo01/1.txt" | 1 + .../demo01/2.txt" | 1 + .../demo01/3.txt" | 1 + .../demo01/4.txt" | 1 + .../fs.js" | 26 ++++++++++++++ .../fs2.js" | 36 +++++++++++++++++++ .../fs3.js" | 18 ++++++++++ .../index.txt" | 1 + 10 files changed, 87 insertions(+) create mode 100644 "\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/a.txt" create mode 100644 "\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/b.txt" create mode 100644 "\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/demo01/1.txt" create mode 100644 "\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/demo01/2.txt" create mode 100644 "\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/demo01/3.txt" create mode 100644 "\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/demo01/4.txt" create mode 100644 "\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/fs.js" create mode 100644 "\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/fs2.js" create mode 100644 "\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/fs3.js" create mode 100644 "\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/index.txt" diff --git "a/\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/a.txt" "b/\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/a.txt" new file mode 100644 index 0000000..5916697 --- /dev/null +++ "b/\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/a.txt" @@ -0,0 +1 @@ +可以测试option \ No newline at end of file diff --git "a/\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/b.txt" "b/\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/b.txt" new file mode 100644 index 0000000..b90c5f0 --- /dev/null +++ "b/\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/b.txt" @@ -0,0 +1 @@ +学习简单的不会晕了哦 \ No newline at end of file diff --git "a/\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/demo01/1.txt" "b/\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/demo01/1.txt" new file mode 100644 index 0000000..56a6051 --- /dev/null +++ "b/\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/demo01/1.txt" @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git "a/\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/demo01/2.txt" "b/\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/demo01/2.txt" new file mode 100644 index 0000000..d8263ee --- /dev/null +++ "b/\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/demo01/2.txt" @@ -0,0 +1 @@ +2 \ No newline at end of file diff --git "a/\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/demo01/3.txt" "b/\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/demo01/3.txt" new file mode 100644 index 0000000..e440e5c --- /dev/null +++ "b/\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/demo01/3.txt" @@ -0,0 +1 @@ +3 \ No newline at end of file diff --git "a/\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/demo01/4.txt" "b/\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/demo01/4.txt" new file mode 100644 index 0000000..bf0d87a --- /dev/null +++ "b/\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/demo01/4.txt" @@ -0,0 +1 @@ +4 \ No newline at end of file diff --git "a/\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/fs.js" "b/\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/fs.js" new file mode 100644 index 0000000..9df5780 --- /dev/null +++ "b/\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/fs.js" @@ -0,0 +1,26 @@ +let fs = require('fs'); + +fs.open('./index.txt','a',function(err,fd){ + if(err){ + console.log(err); + }else{ + let msg = '今天学习异步文件写入,会有点绕哦!'; + bf = Buffer.from(msg); + fs.write(fd,bf,function(err,writeNum,bf2){ + console.log(err); + console.log(writeNum); + //buffer 转字符串 bf.toString() + console.log(bf2.toString()); + console.log(('done!')); + }); + console.log('写入完成!'); + + //异步文件关闭 + fs.close(fd,function(err){ + console.log('异步文件已关闭'); + console.log(err); + }) + } +}); + +console.log('study node fs async'); \ No newline at end of file diff --git "a/\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/fs2.js" "b/\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/fs2.js" new file mode 100644 index 0000000..3cf65c2 --- /dev/null +++ "b/\351\251\254\351\235\222\351\235\222/2022-2.25\345\274\202\346\255\245\347\273\203\344\271\240/fs2.js" @@ -0,0 +1,36 @@ +let fs = require('fs'); + +let createFile = { + //创建文件夹 + createPath:function(dir){ + if(fs.existsSync(dir)){ + return ; + } + fs.mkdirSync(dir); + }, + //创建内容 + createContent:function(num){ + return num+''; + }, + + //写入文件 + createFile:function(filePath,content){ + //flags a 可写 + console.log(filePath); + let fd = fs.openSync(filePath,'a'); + fs.writeSync(fd,content); + fs.closeSync(fd); + }, + handle:function(num,dir){ + //目录不存在则创建 + this.createPath(dir); + //循环的创建文件与内容 + for(let i= 1;i