Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 560
  • Last Modified:

detect platform in java?

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
jenniferx
Asked:
jenniferx
  • 2
1 Solution
 
jenniferxAuthor Commented:
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
 
rajesh_balaCommented:
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
 
poluruCommented:
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
 
jenniferxAuthor Commented:
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now