View Full Version : Check OS in Java

May 14th, 2006, 03:23 PM
Is there a way to check the operating system you are on in Java?

I am making a mario bros. clone for a java project and am doing it on two computers, one is windows, the other is Ubuntu. I need to specify the OS so I can read the images, which are in different directories than the classes. Unless I am mistaken, Ubuntu will use a '/' for a directory and windows uses '\\', and I need it to automatically specify so I dont have to change the code every time i switch platforms.

May 14th, 2006, 03:32 PM
System.getProperty("os.name") and "os.version"
For more information, see google

May 14th, 2006, 03:42 PM
You can check the os, but this really isn't the best way to do it. Java already sets the / or \ in the package java.io.File. Use the variable:


May 15th, 2006, 08:24 PM
thanks! that really helps me out a lot!