当前位置: 技术问答>java相关
如何知道操作系统是windows 还是redhat linux,以及如何调用linux的命令?
来源: 互联网 发布时间:2015-10-19
本文导语: 各位大虾,请问如何知道操作系统是windows 还是redhat linux,以及如何调用linux的命令? | 试试这个:(下面提到的都是java.lang包的类、出特殊说明的) ///////////////////////////////////////////////////////////...
各位大虾,请问如何知道操作系统是windows 还是redhat linux,以及如何调用linux的命令?
|
试试这个:(下面提到的都是java.lang包的类、出特殊说明的)
///////////////////////////////////////////////////////////////////
System
static Properties getProperties()
Determines the current system properties. static String getProperty(String key)
Gets the system property indicated by the specified key.
static String getProperty(String key, String def)
Gets the system property indicated by the specified key.
/////////////////////////////////////////////////////////////////
java.util.Properties
String getProperty(String key)
Searches for the property with the specified key in this property list.
String getProperty(String key, String defaultValue)
Searches for the property with the specified key in this property list.
//////////////////////////////////////////////////////////////////
Runtime
Process exec(String command)
Executes the specified string command in a separate process.
Process exec(String[] cmdarray)
Executes the specified command and arguments in a separate process.
Process exec(String[] cmdarray, String[] envp)
Executes the specified command and arguments in a separate process with the specified environment.
Process exec(String[] cmdarray, String[] envp, File dir)
Executes the specified command and arguments in a separate process with the specified environment and working directory.
Process exec(String cmd, String[] envp)
Executes the specified string command in a separate process with the specified environment.
Process exec(String command, String[] envp, File dir)
Executes the specified string command in a separate process with the specified environment and working directory.
///////////////////////////////////////////////////////////////////
Process
abstract void destroy()
Kills the subprocess.
abstract int exitValue()
Returns the exit value for the subprocess.
abstract InputStream getErrorStream()
Gets the error stream of the subprocess.
abstract InputStream getInputStream()
Gets the input stream of the subprocess.
abstract OutputStream getOutputStream()
Gets the output stream of the subprocess.
abstract int waitFor()
causes the current thread to wait, if necessary, until the process represented by this Process object has terminated.
然后自己看吧!
///////////////////////////////////////////////////////////////////
System
static Properties getProperties()
Determines the current system properties. static String getProperty(String key)
Gets the system property indicated by the specified key.
static String getProperty(String key, String def)
Gets the system property indicated by the specified key.
/////////////////////////////////////////////////////////////////
java.util.Properties
String getProperty(String key)
Searches for the property with the specified key in this property list.
String getProperty(String key, String defaultValue)
Searches for the property with the specified key in this property list.
//////////////////////////////////////////////////////////////////
Runtime
Process exec(String command)
Executes the specified string command in a separate process.
Process exec(String[] cmdarray)
Executes the specified command and arguments in a separate process.
Process exec(String[] cmdarray, String[] envp)
Executes the specified command and arguments in a separate process with the specified environment.
Process exec(String[] cmdarray, String[] envp, File dir)
Executes the specified command and arguments in a separate process with the specified environment and working directory.
Process exec(String cmd, String[] envp)
Executes the specified string command in a separate process with the specified environment.
Process exec(String command, String[] envp, File dir)
Executes the specified string command in a separate process with the specified environment and working directory.
///////////////////////////////////////////////////////////////////
Process
abstract void destroy()
Kills the subprocess.
abstract int exitValue()
Returns the exit value for the subprocess.
abstract InputStream getErrorStream()
Gets the error stream of the subprocess.
abstract InputStream getInputStream()
Gets the input stream of the subprocess.
abstract OutputStream getOutputStream()
Gets the output stream of the subprocess.
abstract int waitFor()
causes the current thread to wait, if necessary, until the process represented by this Process object has terminated.
然后自己看吧!
|
对从系统属性中可以得到
Properties props = System.getProperties();
Enumeration enum = props.propertyNames();
while(enum.hasMoreElements())
{
String name = (String)enum.nextElement();
System.out.print(name + ":");
System.out.println(props.getProperty(name));
}
Properties props = System.getProperties();
Enumeration enum = props.propertyNames();
while(enum.hasMoreElements())
{
String name = (String)enum.nextElement();
System.out.print(name + ":");
System.out.println(props.getProperty(name));
}