Solved

Java detection on Server OS type

Posted on 2006-06-21
6
221 Views
Last Modified: 2012-08-14
Hi, my application potentially will be running on UNIX, ,LINUX, or Window OS.

I am wondering is JAva able to detect which OS i am currently running. I am asking this because sometime my application will neeed to access the location machine directory. For UNIX or FreeBSD the file structure is different comparing with window.

So, i plan to put a if-else condition to check what is the OS i am using so that i can access the directory respectively.

thanks.
0
Comment
Question by:xman19
  • 2
  • 2
  • 2
6 Comments
 
LVL 92

Accepted Solution

by:
objects earned 325 total points
ID: 16956807
String os = System.getProperty("os.name");
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16956891
>> i plan to put a if-else condition to check what is the OS i am using so that i can access the directory respectively

You should ideally put the directory-name in a properties-file so that it can be changed at run-time without modifying the code, rather than hard-code for only certain scenarios in the code.

http://www.javaalmanac.com/egs/java.util/Props.html
0
 

Author Comment

by:xman19
ID: 16957117
object, "os.name"?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:xman19
ID: 16957133
yeah. it;s working and its printing Window XP for me.

I am wondering any other words other than "os.name"?

first look at it, unbeliable it's passing the "os.name" into it. Do i have "os.file"? or "os.yearmanafacture"? or things like that?
0
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 100 total points
ID: 16957156
The list of allowed System properties is available here:

http://java.sun.com/docs/books/tutorial/essential/system/properties.html
0
 
LVL 92

Expert Comment

by:objects
ID: 16957162
its the system property name that specifies the OS
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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…
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

932 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

11 Experts available now in Live!

Get 1:1 Help Now