简体   繁体   English

Java:在Jar中打开xml-File。 无法打开

[英]Java: Open xml-File inside a Jar. Not able to open it

I want to Read a XML-Document which is inside my .jar-File 我想读取.jar文件中的XML文档

When i export into jar (Via Intelliji), the Programm cant find my File (java.io.FileNotFoundException). 当我导出到jar(通过Intelliji)时,程序找不到我的文件(java.io.FileNotFoundException)。 I tried everything (Jar-Path, Classloader etc.) I also Export this file in the Jar. 我尝试了所有方法(Jar-Path,Classloader等),也将文件导出到Jar中。 First the file is in the Project Directory But cant open it, until i extract it.... 首先,该文件位于项目目录中,但无法将其打开,直到将其解压缩为止。

This is the Position in the Project Directory: 这是项目目录中的位置:

inputFile = new File("SommersemesterStundenobjekte.xml");

Also when i give the right Path inside to the jar. 另外,当我将正确的路径放入罐子时。 Not able to open it: 无法打开它:

inputFile = new File(getJarPath() + "\\SommersemesterStundenobjekte.xml "); inputFile =新文件(getJarPath()+“ \\ SommersemesterStundenobjekte.xml”);

java.io.FileNotFoundException: C:\\Users\\thoma\\Desktop\\StundeplanRaunig1.0.3.jar\\SommersemesterStundenobjekte.xml (Das System kann den angegebenen Pfad nicht finden) java.io.FileNotFoundException:C:\\ Users \\ thoma \\ Desktop \\ StundeplanRaunig1.0.3.jar \\ SommersemesterStundenobjekte.xml(Das System kann den angegebenen Pfad nicht finden)

But i want, that the Programm works only with the jar-File. 但是我想,该程序只能与jar文件一起使用。

Please Help :) 请帮忙 :)

Do not use File in this case. 在这种情况下,请勿使用File Use this.getClass().getResourceAsStream("/SommersemesterStundenobjekte.xml") 使用this.getClass().getResourceAsStream("/SommersemesterStundenobjekte.xml")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM