Reputation: 7228
I try to create a fileInputStram
for Jasper i get FileNotFoundException
.
my jasper file and the java class is under the same package.
i use java 1.8 and jasperreport 5.5.0
Does anybody know what is the wrong in this code?
java.io.FileNotFoundException: de\reports\off\office.jasper (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at de.reports.off.PrintOffice.retrieveStream(PrintOffice.java:105)
this is my methode:
public static FileInputStream retrieveStream() {
final String OFFICE_JASPER = "de\\reports\\off\\office.jasper";
File jasperFile = new File( OFFICE_JASPER );
FileInputStream fis = null;
try {
fis = new FileInputStream( jasperFile);
}
catch ( FileNotFoundException e ) {
e.printStackTrace();
}
return fis;
}
Upvotes: 0
Views: 394
Reputation: 22963
If you create a File
object with a relative path, it will be relative the directory specified in user.home
(normally the directory from which you start your application).
example:
- your application is started from directory C:\dir1\app
- the File
will refer to the file C:\dir1\app\de\reports\off\office.jasper
Upvotes: 1
Reputation: 7228
My IDE didn't copy the file when compiling.
It was just small adjustment in pom file where .jasper was defined.
i added /src
to <directory>${basedir}/src</directory>
<resource>
<directory>${basedir}/src</directory>
<filtering>false</filtering>
<includes>
<include>**/*.jasper</include>
</includes>
<excludes>
<exclude>target</exclude>
<exclude>**/target</exclude>
<exclude>**/target/**</exclude>
</excludes>
</resource>
Upvotes: 0