[英]accessing a file inside war folder from a code
I am finding it hard to access a file inside my war
folder from a code in my java web project. 我发现很难从我的java web项目中的代码访问
war
文件夹中的文件。
This is my file structure 这是我的文件结构
the java code I am using is inside the package com.abl.tf.dao
. 我正在使用的java代码在
com.abl.tf.dao
包中。
I am trying to access the the file testreport.jrxml
which is inside the war->reports
folder. 我正在尝试访问
testreport.jrxml
war->reports
文件夹中的文件testreport.jrxml
。
This is what I have tried and this gives me the exception file not found
. 这是我尝试过的,这给了我
file not found
的异常file not found
。
net.sf.jasperreports.engine.design.JasperDesign design = JRXmlLoader.load(
new LegacyJasperInputStream(new FileInputStream("/TFProject/reports/testreport.jrxml"))
);
could you please help me to access that file from the code. 你可以帮我从代码中访问该文件吗?
Thanks in advance! 提前致谢!
You need to access the file as a resource. 您需要将该文件作为资源访问。 You do it like so:
你这样做:
net.sf.jasperreports.engine.design.JasperDesign design = JRXmlLoader.load(new LegacyJasperInputStream(getServletContext().getResourceAsStream("/reports/testreport.jrxml"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.