Results 1 to 4 of 4

Thread: Check OS in Java

  1. #1
    Join Date
    Nov 2005
    Location
    Michigan
    Beans
    538

    Check OS in Java

    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.
    HOWTO: Set up wireless internet (Desktop or laptop)
    Registered Linux User #454618
    2112

  2. #2
    Join Date
    Mar 2006
    Beans
    5

    Re: Check OS in Java

    System.getProperty("os.name") and "os.version"
    For more information, see google

  3. #3
    Join Date
    Oct 2005
    Location
    IN, USA
    Beans
    274

    Re: Check OS in Java

    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:

    Code:
    File.separator

  4. #4
    Join Date
    Nov 2005
    Location
    Michigan
    Beans
    538

    Re: Check OS in Java

    thanks! that really helps me out a lot!
    HOWTO: Set up wireless internet (Desktop or laptop)
    Registered Linux User #454618
    2112

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •