Java:使用OS标准应用程序打开jar中的资源(txt文件) [英] Java: opening a resource (txt file) which is in a jar with OS standard application
问题描述
我收到错误"AWT-EventQueue-0 java.lang.IllegalArgumentException:URI不分层". -我正在尝试使用java.awt.Desktop api使用操作系统的默认应用程序打开文本文件. -我正在运行的应用程序是从autorunning jar启动的. 我了解从文件中获取文件"不是正确的方法,并且将其称为资源.我仍然无法打开它,也无法弄清楚该怎么做.
i get the error "AWT-EventQueue-0 java.lang.IllegalArgumentException: URI is not hierarchical". -I'm trying to use the java.awt.Desktop api to open a text file with the OS's default application. -The application i'm running is launched from the autorunning jar. I understand that getting a "file from a file" is not the correct way and that it's called resource. I still can't open it and can't figure out how to do this.
open(new File((this.getClass().getResource("prova.txt")).toURI()));
是否可以从我的应用程序中使用标准os应用程序打开资源? 谢谢:)
Is there a way to open the resource with the standard os application from my application? Thx :)
推荐答案
您必须将文件从Jar中提取到temp文件夹中,然后打开该临时文件,就像处理Zip文件中的文件一样(基本上是一个Jar).
You'd have to extract the file from the Jar to the temp folder and open that temporary file, much like you would do with files in a Zip-file (which a Jar basically is).
这篇关于Java:使用OS标准应用程序打开jar中的资源(txt文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!