简体   繁体   中英

FileInputStream java.io.FileNotFoundException

I should preface that this code is being run in IBM JDK 7. The following line of code throws a FileNotFound exception.

properties.load(new FileInputStream("/myApp/properties/props.properties"));

The same line of code works fine on my colleagues computers though. For some reason on their machines there is an implicit C: that is assumed in front of that path, which is what I need to happen on my computer. We have put our heads together but haven't figured out a solution to the problem.

When I run this line

properties.load(new FileInputStream("C:\\myApp\\properties\\props.properties"));

It works fine and does not throw an error. As you can see I have specifically put the C: in the path. How can I get the first line of code to assume there is an implicit C: ?

On Windows the file name /myApp/properties/props.properties is not absolute as it does not specifiy a drive letter. The OS will add the drive of the current working directory to make it an absolute file name.

So if the program is started with the current working directory on drive C all is fine, if started from another drive the file will not be found.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM