• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 237
  • Last Modified:

Java detection on Server OS type

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
xman19
Asked:
xman19
  • 2
  • 2
  • 2
2 Solutions
 
objectsCommented:
String os = System.getProperty("os.name");
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> 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
 
xman19Author Commented:
object, "os.name"?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
xman19Author Commented:
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
 
Mayank SAssociate Director - Product EngineeringCommented:
The list of allowed System properties is available here:

http://java.sun.com/docs/books/tutorial/essential/system/properties.html
0
 
objectsCommented:
its the system property name that specifies the OS
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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