1 System1.1 I / O stream L Public Static InputStream IN: Read the standard input stream of characters. l Public Static PrintStream Out: Standard output flow. l Public Static PrintStream Err: Standard Error Output Flow. 1.2 System Attributes (1) Properties L Java.version version number java.vendor vendor L java.class.url java.home Installation Directory l Java.class.Version class java.class.path path l os.name OS. Arch supported architecture l os.Version file.separatorl path.seParetor Line.seParetor line division cleft Line.Name User.home Home Directory L User.dir User Current Directory (2) Method L Public Static Properties GetProperties (): Take System properties. If the current system properties set does not exist, then create and initialize. l Public Static Void SetProperties (Properties Props) L Public Static String getProperty (String Key) Returns the attribute value named KEY. Equivalent to System.getProperties (). GetProperty (key); l Public Static String getProperty (String Key, String DefaultValue) Returns the attribute value called KEY. Returns DefaultValue if it is not defined. It is equivalent to system.getproperties (). GetProperty (key, def); (3) Decoded property value of the attribute value Converts to a value (object) l static boolean boolean.getBoolean (String name) Name is "true" (not distinguishes When you are case you case, return TRUE, otherwise falseger (String name) If there is no digital form, return NULL. l Static Integer Integer.getinteger (String Name, Integer Def): If there is no digital form, return the default value defl static long long.getlong (String nm) L static long long.getlong (String nm, long def) (4) Eamplepublic Static file Personal (String FileName) {string home = system.getProperty ("user.home"); if (home == null) Return Null; else returna; home, filename;} 1.3 security (1) SecurityManagerl Abstract class, enable various security policies L Provide various CHECK methods to control whether to open network interfaces, whether to allow file access, thread creation, etc. (2) System and security L Static Void SetSecurityManager (SecurityManager S) system security management Object. This value can only be set once. In the future, no matter who start the system security mechanism will depend on the previous value and cannot change it.
l Public Static SecurityManager GetSecurityManager () 1.4 Miscellaneous L public static long currenttimemillis () Returns the GMT time in microseconds (starting at 00:00:00 on January 1, 1970) in January 1, 1970). It will not overflow before 292280995. If the complex situation can be used with a DATE class. l Public Static Void ArrayCopy (Object SRC, INT SRCPOS, Object DST DST, INT DSTPOS, INT Count) Copy the count element of SRC [SRCPOS] in the source array to the corresponding elements starting in DST [DSTPOS] in the destination array. 2 Runtime & Process2.1 Runtime Each application corresponds to a Runtime instance, with the running environment, get the getRuntime () method: static runtime getRuntime () L application Unable to create its own Runtime class instance 2.2 memory management (1) Related to methods l Public long freememory (): Returns the number of available memory byout. l Public Long TotalMemory (): Returns the total number of memory bytes. l Void GC (): Make the Java virtual machine recycled in use of memory. l void runfinalization (): Make the ranary () release resources for the Java virtual machine call object, such as file, etc. (2) Examplepublic static void fulgc () {Runtime Rt = runtime.Getruntime (); long isfree = rt.FreeMemory (); Long Wasfree; do {Wasfree = isfree; rt.gc (); isfree = rt.freeMemory ();} while (isfree> Wasfree);} 2.3 Process Management (1) Creating a process (Runtime) ) l Process EXEC (String Command) Throws oxtception All parameters are in string Command, separated by spaces. Such as: string cmd = "/ bin / ls" opts "" DIR; process child = runtime.Getruntime.exec (cmd); l public process exec (string command, string envp []) ENVP: Environmental array, format Name = value, the name in the name can be space L public process exec (String Cmdarray []) CMDARRAY [0] is a command name, and the other is the command line parameter. l Public Process EXEC (String Cmdarray, String Envp []) The newly created process is called a child process. Conversely, creating a process called a parent process. A Process object is returned by EXEC to each created child process. l Note: The reference assignment of the Process instance cannot kill the child process. The child process can be executed synchronously with the existing Java process. (2) Input and output of Process (in Process) l Public Abstract OutputString GetputString () Returns an OutputString connected to the child process, and is written to this stream as an input read.
This stream is buffered. l Public Abstract InputString GetInputString () Returns an InputString connected to the child process, and the data can be read from this stream when the sub-process is output. This stream is buffered. l Public Abstract INPUTSTRING GETERRORSTRING () Returns an inputString connected to a child process error output, and the data can be read from this stream when its error outputs the data. This stream is not buffered so that the error can be reported immediately. l Example public static Process userProg (String cmd) throws IOException {Process proc = Runtime.getRuntime () exec (cmd);. plugTogether (System.in, proc.getOutputString ()); plugTogether (System.out, proc.getInputString ( ))); Plugtogether (system.err, proc.geterrorString ()); returnified () (3) Control (PROCESS) l Abstract Int WaitFor () THROWS InterruptedException Uncertain Waiting Process end, return it to system .exit or equal value (usually 0 success, non-0 failed). If the process is terminated, the value is returned directly. l Public Abstract Int exitValue () Returns the process exit value. If there is no end, IllegalStateException. l Public Abstract void destroy () kills the process. If the process has been completed, what doesn't do it. The Process object collected as a waste zone does not die and only cannot be used.
l Example // We have import java.io. * And java.util. * public string [] ls (string dir, string opts) throws lsfailedException {try {// start up the command string [] cmdarray = {"/ bin . / ls ", opts, dir}: Process child = Runtime.getRuntime () exec (cmdArray); DataInputStream in = new DateInputStream (child.getInputStream ()); // read the command's output Vector lines = new Vector (); String line; while ((line = in.readline ())! = Null) Lines.addelement (line); if (child.waitfor ()! = 0) // if the ls failed throws new lsfailedException (Child.exitValue ))); String [] Retval = new string [lines.size ()]; lines.copyInfo (return); return return;} catch (lsfailedException e) {throw E;} catch (exception e) {throw new lsfailedException (e) .tostring ());}} (4) Void Exit (int status): (Runtime / System) Terminates the currently running Java virtual machine, status code 0 successfully completed tasks, non-0 failed.
l Example: kill all threads in the current group, and then calls the exit public static void safeExit (int status) {// Get the list of all threads Thread myThrd = Thread.currentThread (); ThreadGroup thisGroup = myThrd.getThreadGroup (); int Count (); thread [] thrds = new thread [count 20]; thisgroup.Enumerate (thrds); for (int i = 0; i