From 4d26fa7658e6d36752bad0fe50a984b4c22326f3 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 16 Feb 2023 22:27:36 +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 --- .../readfile.js" | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 "\345\256\230\346\245\240/node\346\226\207\344\273\266\344\275\234\344\270\232/readfile.js" diff --git "a/\345\256\230\346\245\240/node\346\226\207\344\273\266\344\275\234\344\270\232/readfile.js" "b/\345\256\230\346\245\240/node\346\226\207\344\273\266\344\275\234\344\270\232/readfile.js" new file mode 100644 index 0000000..377b8ae --- /dev/null +++ "b/\345\256\230\346\245\240/node\346\226\207\344\273\266\344\275\234\344\270\232/readfile.js" @@ -0,0 +1,32 @@ +'use strict';//使用严格的模式 +var fs = require('fs'); +const { arrayBuffer, text } = require('stream/consumers'); + +//创建文件,,{flag:"a"}->可以使内容重复输出 +//文件中输出内容,并且重复输出里面的内容(内容会叠加输出), +// fs.writeFileSync("./yyo.txt","你好呀~"); + +// 作业:随机生成100个文件,每个文件随机生成一个1到1000的数字, +// 再取出最大值的那个文件。 + var arr = []; + for(let i = 1;i <= 100; i++) { + // var count1 = [0]; + var count1 = (Math.floor(Math.random()*1000) + 1); + var num1 = "./yu"+i+".txt"; + var file = ""+count1+""; + // fs.writeFileSync("./yu"+ i +".txt","这里的随机数字为:" + count1); + fs.writeFileSync(num1,file); + arr.push(Number(file)); + } + //找最大的值 + var max = arr[0]; + var maxFile = ''; + for (var j = 1 ; j <= arr.length;j++){ + if(max < arr[j]){ + max = arr[j]; + arr[j] = maxFile; + maxFile = num1; + } + } + + console.log(maxFile); \ No newline at end of file -- Gitee