Check the Operating System – Java Utility

public class SystemUtility {

private static String OS = System.getProperty(“os.name”).toLowerCase();

/**
* If System is Windows OS
* @return
*/
public static boolean isWindows() {

return (OS.indexOf(“win”) >= 0);

}

/**
* If System OS is Mac
* @return
*/
public static boolean isMac() {

return (OS.indexOf(“mac”) >= 0);

}

/**
* If System OS is Linux/Unix
* @return
*/
public static boolean isUnix() {

return (OS.indexOf(“nix”) >= 0 || OS.indexOf(“nux”) >= 0 || OS.indexOf(“aix”) > 0 );

}

/**
* If System OS is Solaries
* @return
*/
public static boolean isSolaris() {

return (OS.indexOf(“sunos”) >= 0);

}

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
if (isWindows()) {
System.out.println(“This is Windows”);
} else if (isMac()) {
System.out.println(“This is Mac”);
} else if (isUnix()) {
System.out.println(“This is Unix or Linux”);
} else if (isSolaris()) {
System.out.println(“This is Solaris”);
} else {
System.out.println(“Your OS is not support!!”);
}
}
}

About ashokabhat

I am a C,C ,JAVA,Adobe Flex,.NET Programmer Currently working as a Software Developer
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s