Solved

detect platform in java?

Posted on 2001-07-10
4
546 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Running JavaFX on JDeveloper 12C 1 112
Java: anonymous class 4 54
Java ArrayList and if statement 2 55
Setup Eclipse for Andriod development 2 18
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Suggested Courses

734 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