Solved

detect platform in java?

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
backtracking recursion  code 19 58
Java Server Faces parameter pass? 6 50
hibernate example using maven 12 42
String array comparison 4 33
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

770 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