Question

I am trying to open a file platform independent in this way:

FileInputStream file = new FileInputStream("/opt/sampleFile.jasper");

In linux all is right but in windows I am getting the following exception:

java.io.FileNotFoundException: \opt\sampleFile.jasper

In windows I am locating this file in c:\opt\

What is wrong?

Était-ce utile?

La solution

What is the default drive for your application? /opt/ will be C:/opt/ on Windows if this is the drive of your current working directory.

Instead of storing data in a system directory like /opt I would use a directory relative to the user's home directory i.e. System.getProperty("user.home")

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top