how to detect OS in java

S

S!mb@

Hi,

I'm looking for a way to detect on which OS my program is running.
Is there a variable or someting ?

thanks in advance,

jerem.
 
A

Alan Meyer

S!mb@ said:
Hi,

I'm looking for a way to detect on which OS my program is running.
Is there a variable or someting ?

thanks in advance,

jerem.

As a followup to Thomas' correct answer, here's a little
program to show all properties. I haven't done any
real exception handling. If you get the message
"Completed=false", you'll have to check for actual
exceptions like SecurityException.

Alan

import java.util.*;

class GetProp {

public static void main (String[] args) {

boolean completed = false;

try {
Properties py = System.getProperties();
Enumeration e = py.propertyNames();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
String value = System.getProperty (key);
System.out.println (key + " = " + value);
}
completed = true;
}
finally {
System.out.println ("Completed=" + completed);
}
}
}
 
T

Thomas Fritsch

Hi Alan,

Alan said:
I'm looking for a way to detect on which OS my program is running.
Is there a variable or someting ?
...

import java.util.*;

class GetProp {

public static void main (String[] args) {

boolean completed = false;

try {
Properties py = System.getProperties();
Enumeration e = py.propertyNames();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
String value = System.getProperty (key);
System.out.println (key + " = " + value);
}
// BTW: you can replace the 7 lines above by:
System.getProperties().store(System.out, null);
 
J

John B. Matthews

Thomas Fritsch said:
Hi Alan,

Alan said:
S!mb@ said:
I'm looking for a way to detect on which OS my program is running.
Is there a variable or someting ?
...

import java.util.*;

class GetProp {

public static void main (String[] args) {

boolean completed = false;

try {
Properties py = System.getProperties();
Enumeration e = py.propertyNames();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
String value = System.getProperty (key);
System.out.println (key + " = " + value);
}
// BTW: you can replace the 7 lines above by:
System.getProperties().store(System.out, null);
completed = true;
}
finally {
System.out.println ("Completed=" + completed);
}
}
}

Using the store() method is canonical and more economical, but a
security manager may preclude using getProperties(). In
particular, "...if the security manager does not permit the
getProperties operation, it may choose to permit the
getProperty(String) operation."

John
 
A

Andrew Thompson

In
particular, "...if the security manager does not permit the
getProperties operation, it may choose to permit the
getProperty(String) operation."

'Unsigned Applets' is one distinct case in point.

I had to call the properties by name in my unsigned,
java 1.1 compatible properties applet here..
<http://www.physci.org/pc/property.jsp>

In contrast, the Java Glossay's 'WassUp' applet is
signed, and can delve deeply into the system guts..
<http://mindprod.com/wassup.html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top