Class System
public final class System extends Object
- See Also:
Runtime
-
Field Summary
Fields Modifier and Type Field Description static PrintStreamerrDefault error output stream.static InputStreaminDefault input stream.static PrintStreamoutDefault output stream. -
Method Summary
Modifier and Type Method Description static voidarraycopy(Object src, int srcPos, Object dst, int dstPos, int length)Copieslengthelements from the arraysrc, starting at offsetsrcPos, into the arraydst, starting at offsetdstPos.static StringclearProperty(String name)Removes a specific system property.static Consoleconsole()Returns theConsoleassociated with this VM, or null.static longcurrentTimeMillis()Returns the current time in milliseconds since January 1, 1970 00:00:00.0 UTC.static voidexit(int code)Causes the VM to stop running and the program to exit with the given exit status.static voidgc()Indicates to the VM that it would be a good time to run the garbage collector.static Map<String,String>getenv()Returns an unmodifiable map of all environment variables to their values.static Stringgetenv(String name)Returns the value of the environment variable with the given name, or null if no such variable exists.static PropertiesgetProperties()Returns the system properties.static StringgetProperty(String propertyName)Returns the value of a particular system property ornullif no such property exists.static StringgetProperty(String name, String defaultValue)Returns the value of a particular system property.static SecurityManagergetSecurityManager()Returns null.static intidentityHashCode(Object anObject)Returns an integer hash code for the parameter.static ChannelinheritedChannel()Returns the inherited channel from the creator of the current virtual machine.static StringlineSeparator()Returns the system's line separator.static voidload(String pathName)Loads and links the dynamic library that is identified through the specified path.static voidloadLibrary(String libName)Loads and links the library with the specified name.static voidlogE(String message)static voidlogE(String message, Throwable th)static voidlogI(String message)static voidlogI(String message, Throwable th)static voidlogW(String message)static voidlogW(String message, Throwable th)static StringmapLibraryName(String userLibName)Returns the platform specific file name format for the shared library named by the argument.static longnanoTime()Returns the current timestamp of the most precise timer available on the local system, in nanoseconds.static voidrunFinalization()Provides a hint to the VM that it would be useful to attempt to perform any outstanding object finalization.static voidrunFinalizersOnExit(boolean flag)Deprecated.This method is unsafe.static voidsetErr(PrintStream newErr)Sets the standard error output stream to the given user defined output stream.static voidsetIn(InputStream newIn)Sets the standard input stream to the given user defined input stream.static voidsetOut(PrintStream newOut)Sets the standard output stream to the given user defined output stream.static voidsetProperties(Properties p)Sets all system properties.static StringsetProperty(String name, String value)Sets the value of a particular system property.static voidsetSecurityManager(SecurityManager sm)ThrowsSecurityException.
-
Field Details
-
in
Default input stream. -
out
Default output stream. -
err
Default error output stream.
-
-
Method Details
-
setIn
Sets the standard input stream to the given user defined input stream.- Parameters:
newIn- the user defined input stream to set as the standard input stream.
-
setOut
Sets the standard output stream to the given user defined output stream.- Parameters:
newOut- the user defined output stream to set as the standard output stream.
-
setErr
Sets the standard error output stream to the given user defined output stream.- Parameters:
newErr- the user defined output stream to set as the standard error output stream.
-
arraycopy
Copieslengthelements from the arraysrc, starting at offsetsrcPos, into the arraydst, starting at offsetdstPos.The source and destination arrays can be the same array, in which case copying is performed as if the source elements are first copied into a temporary array and then into the destination array.
- Parameters:
src- the source array to copy the content.srcPos- the starting index of the content insrc.dst- the destination array to copy the data into.dstPos- the starting index for the copied content indst.length- the number of elements to be copied.
-
currentTimeMillis
public static long currentTimeMillis()Returns the current time in milliseconds since January 1, 1970 00:00:00.0 UTC.This method always returns UTC times, regardless of the system's time zone. This is often called "Unix time" or "epoch time". Use a
DateFormatinstance to format this time for display to a human.This method shouldn't be used for measuring timeouts or other elapsed time measurements, as changing the system time can affect the results. Use
nanoTime()for that. -
nanoTime
public static long nanoTime()Returns the current timestamp of the most precise timer available on the local system, in nanoseconds. Equivalent to Linux'sCLOCK_MONOTONIC.This timestamp should only be used to measure a duration by comparing it against another timestamp on the same device. Values returned by this method do not have a defined correspondence to wall clock times; the zero value is typically whenever the device last booted. Use
currentTimeMillis()if you want to know what time it is. -
exit
public static void exit(int code)Causes the VM to stop running and the program to exit with the given exit status. IfrunFinalizersOnExit(boolean)has been previously invoked with atrueargument, then all objects will be properly garbage-collected and finalized first. -
gc
public static void gc()Indicates to the VM that it would be a good time to run the garbage collector. Note that this is a hint only. There is no guarantee that the garbage collector will actually be run. -
getenv
Returns the value of the environment variable with the given name, or null if no such variable exists. -
getenv
Returns an unmodifiable map of all environment variables to their values. -
inheritedChannel
Returns the inherited channel from the creator of the current virtual machine.- Returns:
- the inherited
Channelornullif none exists. - Throws:
IOException- if an I/O error occurred.- See Also:
SelectorProvider,SelectorProvider.inheritedChannel()
-
getProperties
Returns the system properties. Note that this is not a copy, so that changes made to the returned Properties object will be reflected in subsequent calls to getProperty and getProperties.- Returns:
- the system properties.
-
getProperty
Returns the value of a particular system property ornullif no such property exists.The following properties are always provided by the Dalvik VM:
Name Meaning Example file.separator File.separator/java.class.path System class path .java.class.version (Not useful on Android) 50.0java.compiler (Not useful on Android) Empty java.ext.dirs (Not useful on Android) Empty java.home Location of the VM on the file system /systemjava.io.tmpdir See File.createTempFile(java.lang.String, java.lang.String)/sdcardjava.library.path Search path for JNI libraries /vendor/lib:/system/libjava.vendor Human-readable VM vendor The Android Projectjava.vendor.url URL for VM vendor's web site http://www.android.com/java.version (Not useful on Android) 0java.specification.version VM libraries version 0.9java.specification.vendor VM libraries vendor The Android Projectjava.specification.name VM libraries name Dalvik Core Libraryjava.vm.version VM implementation version 1.2.0java.vm.vendor VM implementation vendor The Android Projectjava.vm.name VM implementation name Dalvikjava.vm.specification.version VM specification version 0.9java.vm.specification.vendor VM specification vendor The Android Projectjava.vm.specification.name VM specification name Dalvik Virtual Machine Specificationline.separator The system line separator \nos.arch OS architecture armv7los.name OS (kernel) name Linuxos.version OS (kernel) version 2.6.32.9-g103d848path.separator See File.pathSeparator:user.dir Base of non-absolute paths /user.home (Not useful on Android) Empty user.name (Not useful on Android) Empty It is a mistake to try to override any of these. Doing so will have unpredictable results.
- Parameters:
propertyName- the name of the system property to look up.- Returns:
- the value of the specified system property or
nullif the property doesn't exist.
-
getProperty
Returns the value of a particular system property. ThedefaultValuewill be returned if no such property has been found. -
setProperty
Sets the value of a particular system property.- Returns:
- the old value of the property or
nullif the property didn't exist.
-
clearProperty
Removes a specific system property.- Returns:
- the property value or
nullif the property didn't exist. - Throws:
NullPointerException- if the argument isnull.IllegalArgumentException- if the argument is empty.
-
console
Returns theConsoleassociated with this VM, or null. Not all VMs will have an associated console. A console is typically only available for programs run from the command line.- Since:
- 1.6
-
getSecurityManager
Returns null. Android does not useSecurityManager. This method is only provided for source compatibility.- Returns:
- null
-
identityHashCode
Returns an integer hash code for the parameter. The hash code returned is the same one that would be returned by the methodjava.lang.Object.hashCode(), whether or not the object's class has overridden hashCode(). The hash code fornullis0.- Parameters:
anObject- the object to calculate the hash code.- Returns:
- the hash code for the given object.
- See Also:
Object.hashCode()
-
lineSeparator
Returns the system's line separator. On Android, this is"\n". The value comes from the value of theline.separatorsystem property when the VM starts. Later changes to the property will not affect the value returned by this method.- Since:
- 1.7
-
load
Loads and links the dynamic library that is identified through the specified path. This method is similar toloadLibrary(String), but it accepts a full path specification whereasloadLibraryjust accepts the name of the library to load.- Parameters:
pathName- the path of the file to be loaded.
-
loadLibrary
Loads and links the library with the specified name. The mapping of the specified library name to the full path for loading the library is implementation-dependent.- Parameters:
libName- the name of the library to load.- Throws:
UnsatisfiedLinkError- if the library could not be loaded.
-
logE
-
logE
-
logI
-
logI
-
logW
-
logW
-
runFinalization
public static void runFinalization()Provides a hint to the VM that it would be useful to attempt to perform any outstanding object finalization. -
runFinalizersOnExit
Deprecated.This method is unsafe.Ensures that, when the VM is about to exit, all objects are finalized. Note that all finalization which occurs when the system is exiting is performed after all running threads have been terminated.- Parameters:
flag- the flag determines if finalization on exit is enabled.
-
setProperties
Sets all system properties. This does not take a copy; the passed-in object is used directly. Passing null causes the VM to reinitialize the properties to how they were when the VM was started. -
setSecurityManager
ThrowsSecurityException.Security managers do not provide a secure environment for executing untrusted code and are unsupported on Android. Untrusted code cannot be safely isolated within a single VM on Android, so this method always throws a
SecurityException.- Parameters:
sm- a security manager- Throws:
SecurityException- always
-
mapLibraryName
Returns the platform specific file name format for the shared library named by the argument.- Parameters:
userLibName- the name of the library to look up.- Returns:
- the platform specific filename for the library.
-