2

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 ?

Damir
  • 54,277
  • 94
  • 246
  • 365

5 Answers5

2

You can read O.S. by

System.getProperty("os.name");

and then conditionally read properties file

jmj
  • 237,923
  • 42
  • 401
  • 438
2

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

Community
  • 1
  • 1
sfussenegger
  • 35,575
  • 15
  • 95
  • 119
0

you can use

System.getProperty("os.name")
ayush
  • 14,350
  • 11
  • 53
  • 100
0

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.

leonm
  • 6,454
  • 30
  • 38
0

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"

sushil bharwani
  • 29,685
  • 30
  • 94
  • 128