I'm new to java, i have file named config.porperties i put it in this path / home/user/workspace/myproject/config.properties
but when i submitted the jar file
after packaged it i got that it cannot find this file
java.io.FileNotFoundException: config.properties (No such file or directory)
the code
FileInputStream finputstream = new FileInputStream(
"/home/user/workspace/myproject/config.properties");
prop.load(finputstream);
but there is no error in the code i think the problem with jar file that it couldn't read the path !
Hope i can find help, THANKS
I am not sure what happend during "but when i submitted the jar file after packaged it". Your code still tried to load home/user/workspace/myproject/config.properties. So check whether that file exists and is readable.
If you want the file to reside on a different path - you have to change your code as the path is hardcoded.
if you expect the config.properties to be packaged within the jar and loaded from there, change your code to something like
InputStream input = getClass().getResourceAsStream("/classpath/to/my/file/config.properties");
Watch out: Again you are hardcoding a path but you can ensure the file will reside at that location within the jar.
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.