-2

I want to write a Java code which will print the System properties (whether machine's OS is windows or linux) on the machine it runs and store it in a variable.

Thanks in advance!

richakool
  • 1
  • 3
  • 2
    What is the question, what do you want to check exactly? Like a self check if your app can run on the computer it was started on? Do you have any specifics? – skandigraun Sep 27 '18 at 18:24
  • 1
    first - whether the system is Win32 or Unix? Depending on the system the logic will change of the script. – richakool Sep 27 '18 at 18:26
  • 2
    Come on. That's a -1. I even [mistyped](https://www.google.com/search?q=java+get+oeperating+system) but the first result is perfect. – skandigraun Sep 27 '18 at 18:28
  • 3
    Please don't use comments to clarify your question, edit your question instead. – Max Vollmer Sep 27 '18 at 18:30
  • https://stackoverflow.com/questions/25552/get-os-level-system-information This is what I think you are looking for. – ThatPurpleGuy Sep 27 '18 at 18:50

1 Answers1

1

You can use the following to get OS name:

System.getProperty("os.name");

To get a list (set) of all system properties you can use:

System.getProperties().entrySet();

and to print them use:

System.out.println(System.getProperty("os.name"));
//and
System.out.println(System.getProperties().entrySet().toString());
Rishabh Agarwal
  • 1,988
  • 1
  • 16
  • 33