gpt4 book ai didi

java - 如何打开没有扩展名的文件

转载 作者:行者123 更新时间:2023-12-02 08:37:05 24 4
gpt4 key购买 nike

我想尝试打开不带扩展名的文件。当我尝试打开没有扩展名的文件时,系统会显示“打开方式”表单。但是当我尝试使用方法在我的应用程序中打开该文件时:

    private static void openFile(String fileName) throws IOException {
if(Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop();
File file = new File(fileName);
desktop.open(file);
} else {
Runtime.getRuntime().exec(String.format("cmd /c start %s", fileName));
}
}

系统不显示此表格。怎么解决这个问题?

最佳答案

Desktop.open() 启动与文件扩展名关联的应用程序。

关于java - 如何打开没有扩展名的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1310877/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com