用java 获取当前系统信息的

public static void main(String[] args)throws Exception {
System.out.println(System.getProperty("user.home")); //C:\Users\Administrator
System.out.println(System.getProperty("os.name"));//Windows Vista
System.out.println(System.getProperty("os.arch"));//x86
System.out.println(System.getProperty("os.version"));//6.1
System.out.println(System.getProperty("java.version"));//1.6.0_13
System.out.println(System.getProperty("user.name"));//Administrator
System.out.println(System.getProperty("user.dir"));//D:\MyEclipse\workspaces\netctoss_zgs
InetAddress ia=InetAddress.getLocalHost();
System.out.println(ia.getHostAddress()); //192.168.0.100
String os=System.getProperty("os.name");
if(os !=null && os.startsWith("Windows")){
String command="cmd.exe /c ipconfig /all";
Process p=Runtime.getRuntime().exec(command);
BufferedReader br=new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while((line=br.readLine())!=null){
System.out.println(line);
}
}
}
1. os.name     操作系统的名称  
2. os.arch     操作系统的架构  
3. os.version  操作系统的版本  
4. file.separator  文件分隔符(在 UNIX 系统中是“/”)  
5. path.separator  路径分隔符(在 UNIX 系统中是“:”)  
6. line.separator  行分隔符(在 UNIX 系统中是“/n”)  
7. user.name   用户的账户名称  
8. user.home   用户的主目录  
9. user.dir    用户的当前工作目录

猜你喜欢

转载自qnzhl.iteye.com/blog/2201390