The Java system class USES method examples to get system information
- 2020-04-01 02:49:32
- OfStack
Common methods:
long currentTimeMillis(); Gets the value of the milliseconds of the current time
void exit(); Terminates the currently running Java The virtual machine.
public static void Method(){
long l = System.currentTimeMillis();
System.out.println(l);
System.exit();
}
Properties system.getproperties ();
The information obtained by this method is stored in the Properties collection
Since Properties is a subclass of Hashtable, which is a subclass object of the Map collection, pour into the util package
Then the elements in the collection can be fetched by the method of map
The keys and values in this collection are stored as strings and are not defined as generics
public static void Method_Properties(){
//Gets all attributes of the current system
Properties prop = System.getProperties();
//Iterating over the property information in prop, you can also use an iterator
for(Object obj : prop.keySet()){
String value = (String)prop.get(obj);
System.out.println(obj+"==="+value);
//Get the corresponding property information by the key
String value = System.getProperty("os.name");//Returns null if there is no key
System.out.println(value);
}
}
Customize system information in the system
public static void SetProperties(){
System.setProperty("makey","myvalue");
System.out.println(System.getProperty("makey"));
}
Out: standard output, the default is the monitor
In: standard input, the default is the keyboard