Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Check OS

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Check OS

    Hi all,
    I am a new in java
    and i need to check OS of the system
    every where i have "\\" i need to modify to "/"
    So i write something like this in my class Constants
     public static boolean isWindows;

    and in the class Login that is the main class
    private void checkOS() {
            if (System.getProperty("os.name").startsWith("Windows")) {
                Constants.isWindows = true;
            } else {
                Constants.isWindows = false;
            }
     
        }

    So the question is how to use this code or how to modify in the "\\" to "/" what i need to write there?

    Please help me to understand

    Thank you


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Check OS

    Why don't you just use File.pathSeparator?

    Edit- d'oh, I meant File.separator
    Last edited by KevinWorkman; March 7th, 2012 at 08:19 AM.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Mar 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Check OS

    File.pathSeparator return me only "\" or "/", but i need "\\".

    Thank you for your replay, it's a good idea

  4. #4
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Check OS

    If you need this two times, why don't you concatenate the file separator the number of times you want to???

  5. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Check OS

    Quote Originally Posted by andry2181 View Post
    File.pathSeparator return me only "\" or "/", but i need "\\".

    Thank you for your replay, it's a good idea

    I meant File.separator, which is apparently also what you're talking about.

    But do you understand why you need "\\"? For example, print that out, and then compare "\\" to what File.separator returns.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. #6
    Junior Member
    Join Date
    Mar 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Check OS

    Quote Originally Posted by KevinWorkman View Post
    I meant File.separator, which is apparently also what you're talking about.

    But do you understand why you need "\\"? For example, print that out, and then compare "\\" to what File.separator returns.
    Ok thank you

Similar Threads

  1. Can Somebody check this code?
    By manager00104 in forum What's Wrong With My Code?
    Replies: 31
    Last Post: January 30th, 2012, 11:27 AM
  2. Check this code out
    By jwill22 in forum Java Theory & Questions
    Replies: 4
    Last Post: October 11th, 2010, 08:34 PM
  3. how to check the value
    By javaking in forum Java Servlet
    Replies: 2
    Last Post: July 22nd, 2010, 06:56 AM
  4. Can Anyone Check This Link
    By arpitgadle in forum Java Servlet
    Replies: 5
    Last Post: October 7th, 2009, 08:56 AM
  5. Problem in AWT and IFrame implementaion
    By AZBOY2000 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: April 24th, 2009, 03:41 AM