Solved

detect platform in java?

Posted on 2001-07-10
4
532 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now