I am running my Application from a network-share. For example: “\server\startProgramm.bat”
The Code in my startProgramm.bat:
java -jar %~dp0\app.jar
I need to open some config files. It is working local if i try to open them with:
new File("").getAbsolutePath() + "\\" + filename
but not on my Network share.
The config-files are in a subdir of the dir where my jar and bat files are.
The current working directory is (by default) the one your program runs in. You can not change it within java (see here:
Changing the current working directory in Java?
),
the best practice is to just concatenate the server-path and file-name; but i think (not sure) it is also possible to start your program from the server (
java \\server\\path\\myprogwhere there’s a myprog.class in that directory) and make the working directory default to that path.