简体   繁体   中英

how to add file to the specified embedded JAR resource

I am using some API in which there is a class Reader which have a method readXml(String path)

now when i use this method and give some path which in my computer like

           Reader reader = new Reader();
           reader.readXml("C:\\work\\myfile.xml");

it always faile to read the file

In there API documentation it is mentioned

      readXml(java.lang.String resourcePath) 
      Loads the orthography model, from the specified embedded JAR resource.

so do i need to put my file in some embedded jar resources ,if yes what would be the way of doing it and then reading from it

Thanks

The wording is a bit strange, but I think that what the documentation means is that the resource path is a path used by the classloader to load a resource. The file is thus not searched in the file system, but in the classpath, following the rules detailed in ClassLoader.getResource() .

So, the XML file should be accessible from the classpath. Suppose c:\\work is in the classpath, the resource path should thus be "myfile.xml" or "/myfile.xml" depending on how this method is implemented. If c:\\ is in the classpath, then the path should be "work/myfile.xml" or "/work/myfile.xml" .

If this library is a general-purpose API and is well-designed, it should accept something other than a resource path as argument, like a java.io.Reader or java.io.InputStream.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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