In this post, we will see how to retrieve the name of the operating system (OS) under use and current user home & directory information using Java code. In this particular example, we are using ‘System.getProperty’ to get OS name and User Home & Directory.

Simplest way to detect OS name, User home & directory information using Java ...!!! Click To Tweet

NOTE:
I’ve tested the below code on Mac and Windows machines and based on that you’ll see the output as shown below. For Solaris & Linux, you’ll get the output accordingly.

Example

Output:

On Mac

Operating System: Mac OS X
User Directory : /Users/jradmin

On Windows

Operating System : Windows 10
Current User Directory : C:\Users\deepak\javasamples
User Home : C:\Users\deepak

That’s it, it’s that easy to retrieve OS name and User information using Java code. ?

Simplest way to detect OS name, User home & directory information using Java ...!!! Click To Tweet

If you like this post , please check out my other useful blog posts on Rest Assured:

Other Useful References:

Author

  • Deepak Verma

    Deepak Verma is a Test Automation Consultant and Software development Engineer for more than 10 years. His mission is to help you become an In-demand full stack automation tester. He is also the founder of Techndeck, a blog and online coaching platform dedicated to helping you succeed with all the automation basics to advanced testing automation tricks.