使用jar中的文本编辑器打开文本文件

时间:2016-11-26 18:23:25

标签: java eclipse file-io jar

我正在尝试打开存储在jar目录中的文本文件。在Eclipse中运行以下代码片段没有例外:

private void openModelConfiguration() {
    URL url = this.getClass().getResource("ModelConfiguration.txt");
    File file = new File(url.getPath());
    try {
        java.awt.Desktop.getDesktop().edit(file);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

但运行已编译的jar文件会导致IllegalArgumentException。这意味着程序无法在给定路径下找到文本文件。因此,它需要一些其他方式来访问该文件。

0 个答案:

没有答案
相关问题