Solved

detect platform in java?

Posted on 2001-07-10
4
541 Views
Last Modified: 2012-08-14
Hi everyone,

Is there a way in Java to tell what platform a program is running on?  For example, if I was running example.java on a unix machine or on windows, could i test in that program so that it would tell me which one?

Thanks for any suggestions!
Jennifer.

comments please ;)
0
Comment
Question by:jenniferx
  • 2
4 Comments
 

Author Comment

by:jenniferx
ID: 6271880
I'll mention what i'm doing so you can see my real goal.  

I am trying to concatenate a String with a "\" in windows and "/" in Unix.

but i'll be running the program on both platforms, and i'd like it to be the same program (i.e., not make a new program for each platform).

Is that asking too much?

thanks again.
0
 
LVL 10

Accepted Solution

by:
rajesh_bala earned 30 total points
ID: 6271893
import java.io.*;
import java.util.*;
public class Class1
{
     public static void main(String[] args)
     {
          //System.getProperties().list(System.out); /* Lists all the environment settings*/
          System.out.println(System.getProperty("os.name"));
         
     }
}
0
 
LVL 1

Expert Comment

by:poluru
ID: 6271913
where u come across this problem ?
is it while creating a File object or PATH?
if so u can directly know the charecter to use for seperation.

suppose u wanna to create a File object that represents the path "c:\windows"

u can use like this

File f=new File("c:"+File.separator+"windows");

File.separator will return "\" on WINDOWS
and "/" on UNIX
0
 

Author Comment

by:jenniferx
ID: 6271934
Wow!  Thanks a lot, rajesh_bala and poluru!  I learned so much from your two answers.  That was great.

poluru, please go to this page:
http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20148948

Thanks again,
jennifer.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
even odd program using while loop 3 73
how to debug htl and js pages 8 53
program arguments vs VM arguments 4 27
Html split(text) 2 28
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question