file not found exception in jar

前端 未结 4 1243
逝去的感伤
逝去的感伤 2020-12-10 06:07
public class ABC {
    public ABC() {
        File file = new File(\"xyz.xml\");

but when I run my jar as follows:

java -jar filena         


        
4条回答
  •  余生分开走
    2020-12-10 06:43

    The NullPointerException is a clear indication that the file was not found.

    InputStream input=ABC.class.getResourceAsStream("/Element.xml");

    Where is your XML file? If you place it in the same package (directory inside the jar file) as ABC.class, then it should be Element.xml without the leading slash.

提交回复
热议问题