Java Reference
In-Depth Information
Applets are restricted by the SecurityManager from accessing many of
the properties such as the user's directory information. Here we show a section
of code from the program SysProperties ,which can run both as an applet
and as an application. When run as an applet it displays only a fixed subset of the
properties.
...Intheclass SysProperties ...
public void start () {
try {
Properties sysProps = System.getProperties ();
int i = 0;
Enumeration names = sysProps.propertyNames ();
while (names.hasMoreElements ()) {
String key = (String) names.nextElement ();
i++;
print (i +". "+key+ "="+
sysProps.getProperty (key) + "\n");
}
}
catch (Exception e) {
// If browser security manager throws an exception,
// then just ask for the following property values:
String[] key ={
" java.version " ,
" java.vendor " ,
" java.class.version " ,
"os.name",
"os.arch",
"os.version",
"file.separator",
"path.separator",
"line.separator",
};
for (int i=1; i<=key.length; i++) {
print (i+". "+key[i] + "="+
System.getProperty (key[i]) + "\n");
}
}
...
If you run this program as an application, you will see a system properties listing
similar to the output below (line breaks were added in some items to fit the output
within the page here):
 
Search WWH ::




Custom Search