1
+ const fs = require ( 'fs' ) ;
2
+
3
+ // fs.unlink('/tmp/hello', (err) => {
4
+ // if (err) throw err;
5
+ // console.log('成功删除 /tmp/hello');
6
+ // });
7
+
8
+ // try {
9
+ // fs.unlinkSync('/tmp/hello');
10
+ // console.log('successfully deleted /tmp/hello');
11
+ // } catch (err) {
12
+ // console.log(err);
13
+ // }
14
+
15
+ // fs.rename('./tmp/hello.js', './tmp/world.js', (err) => {
16
+ // if (err) throw err;
17
+ // fs.stat('./tmp/world.js', (err, stats) => {
18
+ // if (err) throw err;
19
+ // console.log(`文件属性: ${JSON.stringify(stats)}`);
20
+ // });
21
+ // });
22
+
23
+ // fs.open('/open/some/file.txt', 'r', (err, fd) => {
24
+ // if (err) throw err;
25
+ // fs.close(fd, (err) => {
26
+ // if (err) throw err;
27
+ // });
28
+ // });
29
+
30
+ // fs.open('./global.js', 'r', (err, fd) => {
31
+ // if (err) throw err;
32
+ // fs.close(fd, (err) => {
33
+ // if (err) throw err;
34
+ // });
35
+ // });
36
+
37
+ // const { URL } = require('url');
38
+ // const fileUrl = new URL('file:///tmp/hello');
39
+ // fs.readFileSync(fileUrl);
40
+
41
+ // fs.open('./global.js', 'r', (err, fd) => {
42
+ // if (err) throw err;
43
+ // fs.fstat(fd, (err, stat) => {
44
+ // if (err) throw err;
45
+ // // 各种操作
46
+
47
+ // // 必须关闭文件描述符!
48
+ // fs.close(fd, (err) => {
49
+ // if (err) throw err;
50
+ // });
51
+ // });
52
+ // });
53
+
54
+ // 例子,处理 fs.watch() 监听器。
55
+ // fs.watch('./global.js', { encoding: 'buffer' }, (eventType, filename) => {
56
+ // if (filename) {
57
+ // console.log(filename);
58
+ // // 打印: <Buffer ...>
59
+ // }
60
+ // });
0 commit comments