From e97a4a85ac223eac5ab8fb2d9110a39042ab3be2 Mon Sep 17 00:00:00 2001 From: wuxp <673254877@qq.com> Date: Mon, 28 Feb 2022 12:25:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../0221/dome1.js" | 22 +++++++++++++++++++ .../0221/dome2.js" | 5 +++++ .../0224/demo.txt" | 0 .../0224/fs1.js" | 21 ++++++++++++++++++ .../0224/fs2.js" | 9 ++++++++ .../0228/fsone.js" | 13 +++++++++++ 6 files changed, 70 insertions(+) create mode 100644 "\345\220\264\351\246\231\350\220\215/0221/dome1.js" create mode 100644 "\345\220\264\351\246\231\350\220\215/0221/dome2.js" create mode 100644 "\345\220\264\351\246\231\350\220\215/0224/demo.txt" create mode 100644 "\345\220\264\351\246\231\350\220\215/0224/fs1.js" create mode 100644 "\345\220\264\351\246\231\350\220\215/0224/fs2.js" create mode 100644 "\345\220\264\351\246\231\350\220\215/0228/fsone.js" diff --git "a/\345\220\264\351\246\231\350\220\215/0221/dome1.js" "b/\345\220\264\351\246\231\350\220\215/0221/dome1.js" new file mode 100644 index 0000000..296ff59 --- /dev/null +++ "b/\345\220\264\351\246\231\350\220\215/0221/dome1.js" @@ -0,0 +1,22 @@ +let a = 5; +let b = 3; + +function plus(){ + return a+b; +} +function minus(){ + return a-b; +} +function ride(){ + return a*b; +} +function divide(){ + return a/b; +} + +module.exports ={ + plus:plus, + minus:minus, + ride:ride, + divide:divide +} \ No newline at end of file diff --git "a/\345\220\264\351\246\231\350\220\215/0221/dome2.js" "b/\345\220\264\351\246\231\350\220\215/0221/dome2.js" new file mode 100644 index 0000000..65b6d3e --- /dev/null +++ "b/\345\220\264\351\246\231\350\220\215/0221/dome2.js" @@ -0,0 +1,5 @@ +let index = require('./dome1'); +console.log(index.plus()); +console.log(index.minus()); +console.log(index.ride()); +console.log(index.divide()); \ No newline at end of file diff --git "a/\345\220\264\351\246\231\350\220\215/0224/demo.txt" "b/\345\220\264\351\246\231\350\220\215/0224/demo.txt" new file mode 100644 index 0000000..e69de29 diff --git "a/\345\220\264\351\246\231\350\220\215/0224/fs1.js" "b/\345\220\264\351\246\231\350\220\215/0224/fs1.js" new file mode 100644 index 0000000..3b06150 --- /dev/null +++ "b/\345\220\264\351\246\231\350\220\215/0224/fs1.js" @@ -0,0 +1,21 @@ +let fsSystem = require('fs'); +let str = []; + +let fd=fsSystem.openSync('./demo.txt',"w"); +console.log("文件可操作描述符是"+fd); + +function mine(num){ + if(isNaN(num) && num != null && num > 0){ + console.log("内容为空"); + }else{ + for (let i = 1; i < num; i++) { + str[i] = fsSystem.openSync(`./demo${i}.txt`, "w"); + fsSystem.writeSync(str[i], `${"加入的数为"+Math.ceil(Math.random()*10)}`); + fsSystem.closeSync(str[i]); + } + } + +} +module.exports={ + mine:mine, +}; \ No newline at end of file diff --git "a/\345\220\264\351\246\231\350\220\215/0224/fs2.js" "b/\345\220\264\351\246\231\350\220\215/0224/fs2.js" new file mode 100644 index 0000000..26ed4ee --- /dev/null +++ "b/\345\220\264\351\246\231\350\220\215/0224/fs2.js" @@ -0,0 +1,9 @@ +let file=require("./fs1.js"); + +try{ + file.mine(3) + console.log("写入成功"); + +}catch(error){ + console.log("写入文件失败,原因是" + error.message); +} \ No newline at end of file diff --git "a/\345\220\264\351\246\231\350\220\215/0228/fsone.js" "b/\345\220\264\351\246\231\350\220\215/0228/fsone.js" new file mode 100644 index 0000000..7215ed8 --- /dev/null +++ "b/\345\220\264\351\246\231\350\220\215/0228/fsone.js" @@ -0,0 +1,13 @@ +let fs = require('fs'); + +for (let i = 1; i <= 100; i++) { + let ason = Math.ceil(Math.random()*10) + let fn = fs.openSync('./com.txt','a') + let fd = fs.openSync(`./demo${i}.txt `, "w"); + fs.writeSync(fd, `${ason}`); + fs.writeSync(fn, `${ason}`); + fs.closeSync(fd); +} + + let buffer=fs.readFileSync("./com.txt",{flag:'r',encoding:'utf8'}); + console.log(buffer.toString()); \ No newline at end of file -- Gitee