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 TweetNOTE:
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | public class GetOSNameUserHomeAndDirectory { public static void main(String[] args) { String osName = System.getProperty("os.name"); String currentUserDirectory = System.getProperty("user.dir"); String userHome = System.getProperty("user.home"); System.out.println("Operating System : "+osName); System.out.println("Current User Directory : "+currentUserDirectory); System.out.println("User Home : "+userHome); } } |
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 TweetIf you like this post , please check out my other useful blog posts on Rest Assured:
Other Useful References: