Electron 使用默认方式打开文件
在 Electron 中,可以使用以下代码来使用默认方式打开文件:
const { shell } = require('electron')
shell.openItem('/path/to/file')
其中,shell 模块提供了许多与操作系统交互的功能,包括打开文件、打开外部链接等。openItem() 方法可以打开指定路径的文件或目录,使用操作系统默认的方式打开。
需要注意的是,openItem() 方法是异步的,因此可以使用回调函数来处理打开文件的结果:
shell.openItem('/path/to/file', (err) => {
if (err) {
console.error(err)
} else {
console.log('File opened successfully')
}
})
原文地址: https://www.cveoy.top/t/topic/dxq4 著作权归作者所有。请勿转载和采集!