I am finding it hard to access a file inside my war
folder from a code in my java web project.
This is my file structure
the java code I am using is inside the package com.abl.tf.dao
.
I am trying to access the the file testreport.jrxml
which is inside the war->reports
folder.
This is what I have tried and this gives me the exception 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"));
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.