How to get a file from ressource

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(); System.out.println(xslFilePath); File xsltfile = new File(xslFilePath); System.out.println(xsltfile.getAbsolutePath()+", exist:"+xsltfile.exists()); I got this result: C:\>java -jar test.jar file:/C:/test.jar!/com/test/decision_template.xsl C:\\file:\C:\test.jar!\com\test\decision_template.xsl, exist:false java.io.FileNotFoundException: file:\C:\test.jar!\com\test\decision_template.xsl (Syntaxe du nom de fichier, de rÚpertoire ou de volume incorrecte) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.(FileInputStream.java:120) at com.test.Test.main(Test.java:30) 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前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏