md
- showOpenFilePicker() 获取文件句柄
- showSaveFilePicker() 保存文件句柄
- getFile() //获取文件内容
let study = async () => {
let fileHandle;
[fileHandle] = await window.showOpenFilePicker()
const fileBlob = await fileHandle.getFile()
console.log(await fileBlob.text())
// createWritable()创建一个可写流对象WritableStream
const writable = await fileHandle.createWritable();
// 通过管道将数据传输到文件,write支持流的
await writable.write('contents');
// 管道使用完毕后需要关闭
await writable.close();
}
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
let study = async () => {
const options = {
types: [
{
description: "Hello File Access Api",
accept: {
'text/plain': ['.txt'],
},
},
],
};
return await window.showSaveFilePicker(options);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 参考
编辑 (opens new window)
上次更新: 2023/01/03, 15:17:33