cannot read a file from META-INF

后端 未结 2 1553
不知归路
不知归路 2021-01-01 22:15

I have a big issue doing something really stupid. That is to say open a stream to a resource file in my META-INF folder. I am working on a jar tool and on doing this:

<
2条回答
  •  星月不相逢
    2021-01-01 23:07

    Try removing first slash:

    InputStream schemaIS = this.getClass().getClassLoader().getResourceAsStream("META-INF/schema.xsd");
    

    You need a leading slash if you are calling the getResourceAsStream method on a Class object. On a ClassLoader object, the path is always absolute, and the leading slash is not necessary.

提交回复
热议问题