Solved

Java detection on Server OS type

Posted on 2006-06-21
6
215 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:mayankeagle
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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:mayankeagle
mayankeagle 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This video teaches viewers about errors in exception handling.

708 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

13 Experts available now in Live!

Get 1:1 Help Now