java- reading the properties file outside of jar file












0















I have a simple Java program that connects to a database. The connection is configured in db.properties file. My program works fine.



When I want to compile it into a executable jar file, I will place the properties file in the same folder so user can easily edit the properties file and change the connection settings to their liking. The slight problem here is my dbpath where I have to specify the exact directory to read the properties file.



I was wondering if I can save it in the same folder and set the path to current directory so no matter where the user save the folder, it will always be able to read the db properties without hardcoding the path.



Code:



 Properties props=new Properties();
String dbpath = "C:\Users\nickywan123\Documents\db.properties";
FileInputStream in = new FileInputStream(dbpath);

props.load(in);
in.close();

String driver = props.getProperty("jdbc.driver");
if(driver!=null){
Class.forName(driver);

}

String url=props.getProperty("jdbc.url");
String username=props.getProperty("jdbc.username");
String password=props.getProperty("jdbc.password");

Connection con = DriverManager.getConnection(url,username,password);


I've tried different solutions to get location of jar file such as Get location of JAR file
but it doesn't return the location I want to be able to read it.



I appreciate any suggestion










share|improve this question























  • Put the file into the src/main/Resources folder and have that put into your jar - have a look at the link I provided

    – Scary Wombat
    Nov 21 '18 at 4:38











  • You should use relative path for dependency files. e.g. /resources/db.properties. In this case resources folder should be parallel to the current working directory.

    – Aditya Gupta
    Nov 21 '18 at 4:39











  • possible duplicate of stackoverflow.com/questions/3457918/…

    – secret super star
    Nov 21 '18 at 4:42











  • @ScaryWombat So I have to include the folder along with that file in the folder that contains the jar file, is that correct?

    – Daredevil
    Nov 21 '18 at 4:54











  • If you want to be able to edit the file, then you need to store it on disk (externally). In this it's best to store it in a "well known" location. On windows that might be something like System.getProperty("user.dir") + File.seperator + "AppData/{Appname}/{foldername}/{file}". The reason for doing something like this is because the working directory may not be the same location where the jar/files are installed

    – MadProgrammer
    Nov 21 '18 at 4:55


















0















I have a simple Java program that connects to a database. The connection is configured in db.properties file. My program works fine.



When I want to compile it into a executable jar file, I will place the properties file in the same folder so user can easily edit the properties file and change the connection settings to their liking. The slight problem here is my dbpath where I have to specify the exact directory to read the properties file.



I was wondering if I can save it in the same folder and set the path to current directory so no matter where the user save the folder, it will always be able to read the db properties without hardcoding the path.



Code:



 Properties props=new Properties();
String dbpath = "C:\Users\nickywan123\Documents\db.properties";
FileInputStream in = new FileInputStream(dbpath);

props.load(in);
in.close();

String driver = props.getProperty("jdbc.driver");
if(driver!=null){
Class.forName(driver);

}

String url=props.getProperty("jdbc.url");
String username=props.getProperty("jdbc.username");
String password=props.getProperty("jdbc.password");

Connection con = DriverManager.getConnection(url,username,password);


I've tried different solutions to get location of jar file such as Get location of JAR file
but it doesn't return the location I want to be able to read it.



I appreciate any suggestion










share|improve this question























  • Put the file into the src/main/Resources folder and have that put into your jar - have a look at the link I provided

    – Scary Wombat
    Nov 21 '18 at 4:38











  • You should use relative path for dependency files. e.g. /resources/db.properties. In this case resources folder should be parallel to the current working directory.

    – Aditya Gupta
    Nov 21 '18 at 4:39











  • possible duplicate of stackoverflow.com/questions/3457918/…

    – secret super star
    Nov 21 '18 at 4:42











  • @ScaryWombat So I have to include the folder along with that file in the folder that contains the jar file, is that correct?

    – Daredevil
    Nov 21 '18 at 4:54











  • If you want to be able to edit the file, then you need to store it on disk (externally). In this it's best to store it in a "well known" location. On windows that might be something like System.getProperty("user.dir") + File.seperator + "AppData/{Appname}/{foldername}/{file}". The reason for doing something like this is because the working directory may not be the same location where the jar/files are installed

    – MadProgrammer
    Nov 21 '18 at 4:55
















0












0








0








I have a simple Java program that connects to a database. The connection is configured in db.properties file. My program works fine.



When I want to compile it into a executable jar file, I will place the properties file in the same folder so user can easily edit the properties file and change the connection settings to their liking. The slight problem here is my dbpath where I have to specify the exact directory to read the properties file.



I was wondering if I can save it in the same folder and set the path to current directory so no matter where the user save the folder, it will always be able to read the db properties without hardcoding the path.



Code:



 Properties props=new Properties();
String dbpath = "C:\Users\nickywan123\Documents\db.properties";
FileInputStream in = new FileInputStream(dbpath);

props.load(in);
in.close();

String driver = props.getProperty("jdbc.driver");
if(driver!=null){
Class.forName(driver);

}

String url=props.getProperty("jdbc.url");
String username=props.getProperty("jdbc.username");
String password=props.getProperty("jdbc.password");

Connection con = DriverManager.getConnection(url,username,password);


I've tried different solutions to get location of jar file such as Get location of JAR file
but it doesn't return the location I want to be able to read it.



I appreciate any suggestion










share|improve this question














I have a simple Java program that connects to a database. The connection is configured in db.properties file. My program works fine.



When I want to compile it into a executable jar file, I will place the properties file in the same folder so user can easily edit the properties file and change the connection settings to their liking. The slight problem here is my dbpath where I have to specify the exact directory to read the properties file.



I was wondering if I can save it in the same folder and set the path to current directory so no matter where the user save the folder, it will always be able to read the db properties without hardcoding the path.



Code:



 Properties props=new Properties();
String dbpath = "C:\Users\nickywan123\Documents\db.properties";
FileInputStream in = new FileInputStream(dbpath);

props.load(in);
in.close();

String driver = props.getProperty("jdbc.driver");
if(driver!=null){
Class.forName(driver);

}

String url=props.getProperty("jdbc.url");
String username=props.getProperty("jdbc.username");
String password=props.getProperty("jdbc.password");

Connection con = DriverManager.getConnection(url,username,password);


I've tried different solutions to get location of jar file such as Get location of JAR file
but it doesn't return the location I want to be able to read it.



I appreciate any suggestion







java






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 4:34









DaredevilDaredevil

18010




18010













  • Put the file into the src/main/Resources folder and have that put into your jar - have a look at the link I provided

    – Scary Wombat
    Nov 21 '18 at 4:38











  • You should use relative path for dependency files. e.g. /resources/db.properties. In this case resources folder should be parallel to the current working directory.

    – Aditya Gupta
    Nov 21 '18 at 4:39











  • possible duplicate of stackoverflow.com/questions/3457918/…

    – secret super star
    Nov 21 '18 at 4:42











  • @ScaryWombat So I have to include the folder along with that file in the folder that contains the jar file, is that correct?

    – Daredevil
    Nov 21 '18 at 4:54











  • If you want to be able to edit the file, then you need to store it on disk (externally). In this it's best to store it in a "well known" location. On windows that might be something like System.getProperty("user.dir") + File.seperator + "AppData/{Appname}/{foldername}/{file}". The reason for doing something like this is because the working directory may not be the same location where the jar/files are installed

    – MadProgrammer
    Nov 21 '18 at 4:55





















  • Put the file into the src/main/Resources folder and have that put into your jar - have a look at the link I provided

    – Scary Wombat
    Nov 21 '18 at 4:38











  • You should use relative path for dependency files. e.g. /resources/db.properties. In this case resources folder should be parallel to the current working directory.

    – Aditya Gupta
    Nov 21 '18 at 4:39











  • possible duplicate of stackoverflow.com/questions/3457918/…

    – secret super star
    Nov 21 '18 at 4:42











  • @ScaryWombat So I have to include the folder along with that file in the folder that contains the jar file, is that correct?

    – Daredevil
    Nov 21 '18 at 4:54











  • If you want to be able to edit the file, then you need to store it on disk (externally). In this it's best to store it in a "well known" location. On windows that might be something like System.getProperty("user.dir") + File.seperator + "AppData/{Appname}/{foldername}/{file}". The reason for doing something like this is because the working directory may not be the same location where the jar/files are installed

    – MadProgrammer
    Nov 21 '18 at 4:55



















Put the file into the src/main/Resources folder and have that put into your jar - have a look at the link I provided

– Scary Wombat
Nov 21 '18 at 4:38





Put the file into the src/main/Resources folder and have that put into your jar - have a look at the link I provided

– Scary Wombat
Nov 21 '18 at 4:38













You should use relative path for dependency files. e.g. /resources/db.properties. In this case resources folder should be parallel to the current working directory.

– Aditya Gupta
Nov 21 '18 at 4:39





You should use relative path for dependency files. e.g. /resources/db.properties. In this case resources folder should be parallel to the current working directory.

– Aditya Gupta
Nov 21 '18 at 4:39













possible duplicate of stackoverflow.com/questions/3457918/…

– secret super star
Nov 21 '18 at 4:42





possible duplicate of stackoverflow.com/questions/3457918/…

– secret super star
Nov 21 '18 at 4:42













@ScaryWombat So I have to include the folder along with that file in the folder that contains the jar file, is that correct?

– Daredevil
Nov 21 '18 at 4:54





@ScaryWombat So I have to include the folder along with that file in the folder that contains the jar file, is that correct?

– Daredevil
Nov 21 '18 at 4:54













If you want to be able to edit the file, then you need to store it on disk (externally). In this it's best to store it in a "well known" location. On windows that might be something like System.getProperty("user.dir") + File.seperator + "AppData/{Appname}/{foldername}/{file}". The reason for doing something like this is because the working directory may not be the same location where the jar/files are installed

– MadProgrammer
Nov 21 '18 at 4:55







If you want to be able to edit the file, then you need to store it on disk (externally). In this it's best to store it in a "well known" location. On windows that might be something like System.getProperty("user.dir") + File.seperator + "AppData/{Appname}/{foldername}/{file}". The reason for doing something like this is because the working directory may not be the same location where the jar/files are installed

– MadProgrammer
Nov 21 '18 at 4:55














1 Answer
1






active

oldest

votes


















2















I will place the properties file in the same folder so user can easily edit the properties file and change the connection settings to their liking




The problem you're facing comes down to the fact that the working directory, where the application is run, may not be the same as the location the application and its files are stored. You can not rely on the location been fixed.



Instead, you should adopt the conventions of the platform and store the files in a "common" location (which is fixed).



On windows that might be ...



System.getProperty("user.dir") + "/AppData/{App name}/{folder name}/{file}"


On MacOS that might be ...



System.getProperty("user.dir") + "/Library/Application Support/{App name}/{folder name}/{file}"


On Linux that might be ...



System.getProperty("user.dir") + ".{Appname}/{folder name}/file"



What about this, the jar file and properties file should be in the same FOLDER. Then user can decide where they want to store/keep the folder, which is the best solution to this?




Doesn't matter, you still run the risk of the "working directory" been different from the "installation directory", which is "why" the above solution was developed - this is not just a Java issue, but affects all programs



You may also run into issues with OS privileges ... looking at you Windows 😠



"Another" solution is allowing the user to pass in the file/location via the command line, allowing them to run the Jar from anywhere, while allowing them to specify the location of the properties file they want to use ... meaning they could have more the one based on there needs






share|improve this answer


























  • Thanks for the reply, so if you store the file in a common location, wouldn't that be a problem because a user might want to store the jar file along with the properties file ,say in his own folder. And he just wants to amend the properties file and run the jar file so it reflects on the changes.?

    – Daredevil
    Nov 21 '18 at 5:05











  • That’s kind of the point - the jar and properties file are independent of each other, so the location in which the jar is installed, which can be different from where it’s run don’t effect your ability to find the file. The other solution is to allow the user to specify the file then selves, perhaps passing it as a command line argument

    – MadProgrammer
    Nov 21 '18 at 5:55











  • What about this, the jar file and properties file should be in the same FOLDER. Then user can decide where they want to store/keep the folder, which is the best solution to this?

    – Daredevil
    Nov 21 '18 at 6:03











  • Doesn't matter, you still run the risk of the "working directory" been different from the "installation directory", which is "why" the above solution was developed - this is not just a Java issue, but affects all programs

    – MadProgrammer
    Nov 21 '18 at 6:17











  • So keep the file properties in a different location than the jar file , is that right?

    – Daredevil
    Nov 21 '18 at 6:21











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405312%2fjava-reading-the-properties-file-outside-of-jar-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2















I will place the properties file in the same folder so user can easily edit the properties file and change the connection settings to their liking




The problem you're facing comes down to the fact that the working directory, where the application is run, may not be the same as the location the application and its files are stored. You can not rely on the location been fixed.



Instead, you should adopt the conventions of the platform and store the files in a "common" location (which is fixed).



On windows that might be ...



System.getProperty("user.dir") + "/AppData/{App name}/{folder name}/{file}"


On MacOS that might be ...



System.getProperty("user.dir") + "/Library/Application Support/{App name}/{folder name}/{file}"


On Linux that might be ...



System.getProperty("user.dir") + ".{Appname}/{folder name}/file"



What about this, the jar file and properties file should be in the same FOLDER. Then user can decide where they want to store/keep the folder, which is the best solution to this?




Doesn't matter, you still run the risk of the "working directory" been different from the "installation directory", which is "why" the above solution was developed - this is not just a Java issue, but affects all programs



You may also run into issues with OS privileges ... looking at you Windows 😠



"Another" solution is allowing the user to pass in the file/location via the command line, allowing them to run the Jar from anywhere, while allowing them to specify the location of the properties file they want to use ... meaning they could have more the one based on there needs






share|improve this answer


























  • Thanks for the reply, so if you store the file in a common location, wouldn't that be a problem because a user might want to store the jar file along with the properties file ,say in his own folder. And he just wants to amend the properties file and run the jar file so it reflects on the changes.?

    – Daredevil
    Nov 21 '18 at 5:05











  • That’s kind of the point - the jar and properties file are independent of each other, so the location in which the jar is installed, which can be different from where it’s run don’t effect your ability to find the file. The other solution is to allow the user to specify the file then selves, perhaps passing it as a command line argument

    – MadProgrammer
    Nov 21 '18 at 5:55











  • What about this, the jar file and properties file should be in the same FOLDER. Then user can decide where they want to store/keep the folder, which is the best solution to this?

    – Daredevil
    Nov 21 '18 at 6:03











  • Doesn't matter, you still run the risk of the "working directory" been different from the "installation directory", which is "why" the above solution was developed - this is not just a Java issue, but affects all programs

    – MadProgrammer
    Nov 21 '18 at 6:17











  • So keep the file properties in a different location than the jar file , is that right?

    – Daredevil
    Nov 21 '18 at 6:21
















2















I will place the properties file in the same folder so user can easily edit the properties file and change the connection settings to their liking




The problem you're facing comes down to the fact that the working directory, where the application is run, may not be the same as the location the application and its files are stored. You can not rely on the location been fixed.



Instead, you should adopt the conventions of the platform and store the files in a "common" location (which is fixed).



On windows that might be ...



System.getProperty("user.dir") + "/AppData/{App name}/{folder name}/{file}"


On MacOS that might be ...



System.getProperty("user.dir") + "/Library/Application Support/{App name}/{folder name}/{file}"


On Linux that might be ...



System.getProperty("user.dir") + ".{Appname}/{folder name}/file"



What about this, the jar file and properties file should be in the same FOLDER. Then user can decide where they want to store/keep the folder, which is the best solution to this?




Doesn't matter, you still run the risk of the "working directory" been different from the "installation directory", which is "why" the above solution was developed - this is not just a Java issue, but affects all programs



You may also run into issues with OS privileges ... looking at you Windows 😠



"Another" solution is allowing the user to pass in the file/location via the command line, allowing them to run the Jar from anywhere, while allowing them to specify the location of the properties file they want to use ... meaning they could have more the one based on there needs






share|improve this answer


























  • Thanks for the reply, so if you store the file in a common location, wouldn't that be a problem because a user might want to store the jar file along with the properties file ,say in his own folder. And he just wants to amend the properties file and run the jar file so it reflects on the changes.?

    – Daredevil
    Nov 21 '18 at 5:05











  • That’s kind of the point - the jar and properties file are independent of each other, so the location in which the jar is installed, which can be different from where it’s run don’t effect your ability to find the file. The other solution is to allow the user to specify the file then selves, perhaps passing it as a command line argument

    – MadProgrammer
    Nov 21 '18 at 5:55











  • What about this, the jar file and properties file should be in the same FOLDER. Then user can decide where they want to store/keep the folder, which is the best solution to this?

    – Daredevil
    Nov 21 '18 at 6:03











  • Doesn't matter, you still run the risk of the "working directory" been different from the "installation directory", which is "why" the above solution was developed - this is not just a Java issue, but affects all programs

    – MadProgrammer
    Nov 21 '18 at 6:17











  • So keep the file properties in a different location than the jar file , is that right?

    – Daredevil
    Nov 21 '18 at 6:21














2












2








2








I will place the properties file in the same folder so user can easily edit the properties file and change the connection settings to their liking




The problem you're facing comes down to the fact that the working directory, where the application is run, may not be the same as the location the application and its files are stored. You can not rely on the location been fixed.



Instead, you should adopt the conventions of the platform and store the files in a "common" location (which is fixed).



On windows that might be ...



System.getProperty("user.dir") + "/AppData/{App name}/{folder name}/{file}"


On MacOS that might be ...



System.getProperty("user.dir") + "/Library/Application Support/{App name}/{folder name}/{file}"


On Linux that might be ...



System.getProperty("user.dir") + ".{Appname}/{folder name}/file"



What about this, the jar file and properties file should be in the same FOLDER. Then user can decide where they want to store/keep the folder, which is the best solution to this?




Doesn't matter, you still run the risk of the "working directory" been different from the "installation directory", which is "why" the above solution was developed - this is not just a Java issue, but affects all programs



You may also run into issues with OS privileges ... looking at you Windows 😠



"Another" solution is allowing the user to pass in the file/location via the command line, allowing them to run the Jar from anywhere, while allowing them to specify the location of the properties file they want to use ... meaning they could have more the one based on there needs






share|improve this answer
















I will place the properties file in the same folder so user can easily edit the properties file and change the connection settings to their liking




The problem you're facing comes down to the fact that the working directory, where the application is run, may not be the same as the location the application and its files are stored. You can not rely on the location been fixed.



Instead, you should adopt the conventions of the platform and store the files in a "common" location (which is fixed).



On windows that might be ...



System.getProperty("user.dir") + "/AppData/{App name}/{folder name}/{file}"


On MacOS that might be ...



System.getProperty("user.dir") + "/Library/Application Support/{App name}/{folder name}/{file}"


On Linux that might be ...



System.getProperty("user.dir") + ".{Appname}/{folder name}/file"



What about this, the jar file and properties file should be in the same FOLDER. Then user can decide where they want to store/keep the folder, which is the best solution to this?




Doesn't matter, you still run the risk of the "working directory" been different from the "installation directory", which is "why" the above solution was developed - this is not just a Java issue, but affects all programs



You may also run into issues with OS privileges ... looking at you Windows 😠



"Another" solution is allowing the user to pass in the file/location via the command line, allowing them to run the Jar from anywhere, while allowing them to specify the location of the properties file they want to use ... meaning they could have more the one based on there needs







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 '18 at 6:22

























answered Nov 21 '18 at 5:02









MadProgrammerMadProgrammer

299k17154267




299k17154267













  • Thanks for the reply, so if you store the file in a common location, wouldn't that be a problem because a user might want to store the jar file along with the properties file ,say in his own folder. And he just wants to amend the properties file and run the jar file so it reflects on the changes.?

    – Daredevil
    Nov 21 '18 at 5:05











  • That’s kind of the point - the jar and properties file are independent of each other, so the location in which the jar is installed, which can be different from where it’s run don’t effect your ability to find the file. The other solution is to allow the user to specify the file then selves, perhaps passing it as a command line argument

    – MadProgrammer
    Nov 21 '18 at 5:55











  • What about this, the jar file and properties file should be in the same FOLDER. Then user can decide where they want to store/keep the folder, which is the best solution to this?

    – Daredevil
    Nov 21 '18 at 6:03











  • Doesn't matter, you still run the risk of the "working directory" been different from the "installation directory", which is "why" the above solution was developed - this is not just a Java issue, but affects all programs

    – MadProgrammer
    Nov 21 '18 at 6:17











  • So keep the file properties in a different location than the jar file , is that right?

    – Daredevil
    Nov 21 '18 at 6:21



















  • Thanks for the reply, so if you store the file in a common location, wouldn't that be a problem because a user might want to store the jar file along with the properties file ,say in his own folder. And he just wants to amend the properties file and run the jar file so it reflects on the changes.?

    – Daredevil
    Nov 21 '18 at 5:05











  • That’s kind of the point - the jar and properties file are independent of each other, so the location in which the jar is installed, which can be different from where it’s run don’t effect your ability to find the file. The other solution is to allow the user to specify the file then selves, perhaps passing it as a command line argument

    – MadProgrammer
    Nov 21 '18 at 5:55











  • What about this, the jar file and properties file should be in the same FOLDER. Then user can decide where they want to store/keep the folder, which is the best solution to this?

    – Daredevil
    Nov 21 '18 at 6:03











  • Doesn't matter, you still run the risk of the "working directory" been different from the "installation directory", which is "why" the above solution was developed - this is not just a Java issue, but affects all programs

    – MadProgrammer
    Nov 21 '18 at 6:17











  • So keep the file properties in a different location than the jar file , is that right?

    – Daredevil
    Nov 21 '18 at 6:21

















Thanks for the reply, so if you store the file in a common location, wouldn't that be a problem because a user might want to store the jar file along with the properties file ,say in his own folder. And he just wants to amend the properties file and run the jar file so it reflects on the changes.?

– Daredevil
Nov 21 '18 at 5:05





Thanks for the reply, so if you store the file in a common location, wouldn't that be a problem because a user might want to store the jar file along with the properties file ,say in his own folder. And he just wants to amend the properties file and run the jar file so it reflects on the changes.?

– Daredevil
Nov 21 '18 at 5:05













That’s kind of the point - the jar and properties file are independent of each other, so the location in which the jar is installed, which can be different from where it’s run don’t effect your ability to find the file. The other solution is to allow the user to specify the file then selves, perhaps passing it as a command line argument

– MadProgrammer
Nov 21 '18 at 5:55





That’s kind of the point - the jar and properties file are independent of each other, so the location in which the jar is installed, which can be different from where it’s run don’t effect your ability to find the file. The other solution is to allow the user to specify the file then selves, perhaps passing it as a command line argument

– MadProgrammer
Nov 21 '18 at 5:55













What about this, the jar file and properties file should be in the same FOLDER. Then user can decide where they want to store/keep the folder, which is the best solution to this?

– Daredevil
Nov 21 '18 at 6:03





What about this, the jar file and properties file should be in the same FOLDER. Then user can decide where they want to store/keep the folder, which is the best solution to this?

– Daredevil
Nov 21 '18 at 6:03













Doesn't matter, you still run the risk of the "working directory" been different from the "installation directory", which is "why" the above solution was developed - this is not just a Java issue, but affects all programs

– MadProgrammer
Nov 21 '18 at 6:17





Doesn't matter, you still run the risk of the "working directory" been different from the "installation directory", which is "why" the above solution was developed - this is not just a Java issue, but affects all programs

– MadProgrammer
Nov 21 '18 at 6:17













So keep the file properties in a different location than the jar file , is that right?

– Daredevil
Nov 21 '18 at 6:21





So keep the file properties in a different location than the jar file , is that right?

– Daredevil
Nov 21 '18 at 6:21


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405312%2fjava-reading-the-properties-file-outside-of-jar-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

Origin of the phrase “under your belt”?