try {
const fileHandle = await window.showSaveFilePicker({
suggestedName: 'my_custom_file.txt', // 提供一个默认的文件名
types: [{
description: 'Text Files',
accept: { 'text/plain': ['.txt'] }
}]
});
// 创建一个写入文件的流
const writable = await fileHandle.createWritable();
// 写入内容
await writable.write('Hello, world! This is a file saved using File System Access API.');
// 关闭文件句柄,保存文件
await writable.close();
alert("文件保存成功!");
} catch (error) {
console.error("保存文件时出错:", error);
}