I know it seems like my question has been answered before, but I can't find an answer for my case.
What I am trying to do, is to get a File type from resource, so when it's packaged, it can be accessed. The answers I found were trying to read that file, but what I really need, is to construct a File object, because I have a third party library that is expecting that object.
Here is a the code I tried:
String xslFilePath = new Test().getClass().getResource("/com/test/decision_template.xsl").getPath();
File xsltfile = new File(xslFilePath);
I got this result:
C:\>java -jar test.jar
(Syntaxe du nom de fichier, de rÃšpertoire ou de volume incorrecte)
at java.io.FileInputStream.open(Native Method)
I need a way to get that file so the .exists() return true. This question already has many answers for you: stackoverflow.com/questions/403256/â€¦. The most reasonable thing to do would be to not require a file, but just an InputStream in general.
以上就是How to get a file from ressource的详细内容，更多请关注web前端其它相关文章！