I have Java app which runs on Linux and Windows and app depends of path of some program ( I need to read two paths in my app, one if I on windows and second if I on Linux, I read which OS in my code ). How to achive this with property file ?
5 Answers
You can read O.S. by
System.getProperty("os.name");
and then conditionally read properties file

- 237,923
- 42
- 401
- 438
What about simply adding both properties?
org.example.linux.path=...
org.example.windows.path=...
And read the property you need
String path = props.getProperty("org.example." + getOS() + ".path");
EDIT: btw, you can get an idea of different system properties and their respective values from this question

- 1
- 1

- 35,575
- 15
- 95
- 119
You have a property file for each OS and decide which one to load depending on the operating system you run on. For example linux.properties will contain the Linux paths while windows.properties will contain the windows paths.

- 6,454
- 30
- 38
just a thought not necessarily correct. Can we try having a property with key as
DS = "\" for one operating system and DS1 = "/" for another operating system and we select it on the basis of whether i am on windows or mozilla.
and we save paths as
path = "c:".DS."dir1".DS."dir2"

- 29,685
- 30
- 94
- 128