java获取系统相关信息_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > java获取系统相关信息

java获取系统相关信息

 2012/1/13 9:06:34  bcworld  程序员俱乐部  我要评论(0)
  • 摘要:下面的代码可以获取系统的环境变量,操作系统、处理器、编码和语言等各种信息。importjava.nio.charset.Charset;importjava.util.Iterator;importjava.util.Map;importjava.util.Properties;importjava.util.Set;publicclassSystemProperty{publicstaticvoidmain(String[]args){System.out.println
  • 标签:Java

下面的代码可以获取系统的环境变量,操作系统、处理器编码和语言等各种信息。

import java.nio.charset.Charset;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class SystemProperty {
	public static void main(String[] args) {
		System.out.println("****************getenv**************");
		int index = 1;
		Map<String, String> map = System.getenv();
		Set<String> set = map.keySet();
		Iterator<String> iterator = set.iterator();
		String temp = "";
		while (iterator.hasNext()) {
			temp = (String) iterator.next();
			System.out.println((index++) + "\t" + temp.toLowerCase() + "="
					+ map.get(temp));
		}
		System.out.println("****************getProperties**************");
		Properties properties = System.getProperties();
		Set<Object> pSet = properties.keySet();
		Iterator<Object> pIterator = pSet.iterator();
		index = 1;
		while (pIterator.hasNext()) {
			temp = (String) pIterator.next();
			System.out.println((index++) + "\t" + temp + "="
					+ properties.getProperty(temp));
		}
		System.out.println("*******获得Java支持编码集合:*********");
		set = Charset.availableCharsets().keySet();
		iterator = set.iterator();
		index=1;
		while (iterator.hasNext()) {
			String string = (String) iterator.next();
			System.out.println((index++) + "\t" + string);
		}
		System.out.println("*******获获得系统默认编码:*********");
		// Locale.setDefault(new Locale("en", "us"));
		Charset charset = Charset.defaultCharset();
		String name = charset.name();
		String displayName = charset.displayName();
		System.out.println("name=" + name + ",displayName=" + displayName);
                Locale defaultL = Locale.getDefault();
		System.out.println("系统默认语言:" + defaultL.getLanguage() + "\t"
				+ defaultL.getDisplayCountry() + "\t" + defaultL.getCountry());
		Locale[] locale = Locale.getAvailableLocales();
		index=1;
		for (Locale l : locale) {
			System.out.println("--------------"+(index++)+"----------------");
			System.out.println(l.getCountry() + "\t" + l.getDisplayCountry());
			System.out.println(l.getLanguage() + "\t" + l.getDisplayLanguage());
			System.out.println(l.getISO3Country());
			System.out.println(l.getDisplayName());
			System.out.println(l.getVariant() + "\t" + l.getDisplayVariant());
		}
?}
}

?其中,file.encoding=GBK指的是你的java源码的编码,如果你将源码保存为UTF-8,那么file.encoding=UTF-8.

运行程序后,结果如下:

****************getenv**************
1??? userprofile=C:\Documents and Settings\Administrator
2??? pathext=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
3??? java_home=C:\Program Files\Java\jdk1.6.0_13
4??? temp=C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp
5??? systemdrive=C:
6??? programfiles=C:\Program Files
7??? path=C:/Program Files/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;C:/Program Files/Java/jre6/lib/i386;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\MySQL\MySQL Server 5.1\bin;.;C:\Program Files\Java\jdk1.6.0_13\bin;C:\Program Files\StormII\Codec;C:\Program Files\StormII;C:\Program Files\erl5.8.4\bin;;C:\Program Files\eclipse;
8??? homedrive=C:
9??? processor_revision=170a
10??? clientname=Console
11??? userdomain=PC-20100116102
12??? allusersprofile=C:\Documents and Settings\All Users
13??? processor_identifier=x86 Family 6 Model 23 Stepping 10, GenuineIntel
14??? sessionname=Console
15??? tmp=C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp
16??? commonprogramfiles=C:\Program Files\Common Files
17??? =::=::\
18??? logonserver=\\PC-20100116102
19??? processor_architecture=x86
20??? fp_no_host_check=NO
21??? os=Windows_NT
22??? homepath=\Documents and Settings\Administrator
23??? vs100comntools=D:\Program Files\vs2010\Common7\Tools\
24??? processor_level=6
25??? classpath=.;C:\Program Files\Java\jdk1.6.0_13\lib\da.jar;C:\Program Files\Java\jdk1.6.0_13\lib\tools.jar;C:\sqlserver2005jar\sqljdbc.jar;C:\Program Files\Java\jre6\lib\rt.jar;
26??? catalina_home=E:\tomcat
27??? lib=C:\Program Files\SQLXML 4.0\bin\
28??? computername=PC-20100116102
29??? windir=C:\WINDOWS
30??? systemroot=C:\WINDOWS
31??? number_of_processors=2
32??? username=Administrator
33??? comspec=C:\WINDOWS\system32\cmd.exe
34??? appdata=C:\Documents and Settings\Administrator\Application Data
****************getProperties**************
1??? java.runtime.name=Java(TM) SE Runtime Environment
2??? sun.boot.library.path=C:\Program Files\Java\jdk1.6.0_13\jre\bin
3??? java.vm.version=11.3-b02
4??? java.vm.vendor=Sun Microsystems Inc.
5??? java.vendor.url=http://java.sun.com/
6??? path.separator=;
7??? java.vm.name=Java HotSpot(TM) Client VM
8??? file.encoding.pkg=sun.io
9??? sun.java.launcher=SUN_STANDARD
10??? user.country=CN
11??? sun.os.patch.level=Service Pack 3
12??? java.vm.specification.name=Java Virtual Machine Specification
13??? user.dir=E:\ECLIPSEPROJECT\EclipseProject\core
14??? java.runtime.version=1.6.0_13-b03
15??? java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment
16??? java.endorsed.dirs=C:\Program Files\Java\jdk1.6.0_13\jre\lib\endorsed
17??? os.arch=x86
18??? java.io.tmpdir=C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\
19??? line.separator=

20??? java.vm.specification.vendor=Sun Microsystems Inc.
21??? user.variant=
22??? os.name=Windows XP
23??? sun.jnu.encoding=GBK
24??? java.library.path=C:\Program Files\Java\jdk1.6.0_13\jre\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;C:/Program Files/Java/jre6/lib/i386;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Common Files\Thunder Network\KanKan\Codecs;C:\Program Files\MySQL\MySQL Server 5.1\bin;.;C:\Program Files\Java\jdk1.6.0_13\bin;C:\Program Files\erl5.8.4\bin;;C:\Program Files\eclipse;
25??? java.specification.name=Java Platform API Specification
26??? java.class.version=50.0
27??? sun.management.compiler=HotSpot Client Compiler
28??? os.version=5.1
29??? user.home=C:\Documents and Settings\Administrator
30??? user.timezone=
31??? java.awt.printerjob=sun.awt.windows.WPrinterJob
32??? file.encoding=GBK
33??? java.specification.version=1.6
34??? java.class.path=E:\ECLIPSEPROJECT\EclipseProject\core\bin;D:\libforjava\dom4j\dom4j-1.6.1.jar;D:\libforjava\dom4j\jaxen-1.1-beta-6.jar
35??? user.name=Administrator
36??? java.vm.specification.version=1.0
37??? java.home=C:\Program Files\Java\jdk1.6.0_13\jre
38??? sun.arch.data.model=32
39??? user.language=zh
40??? java.specification.vendor=Sun Microsystems Inc.
41??? awt.toolkit=sun.awt.windows.WToolkit
42??? java.vm.info=mixed mode
43??? java.version=1.6.0_13
44??? java.ext.dirs=C:\Program Files\Java\jdk1.6.0_13\jre\lib\ext;C:\WINDOWS\Sun\Java\lib\ext
45??? sun.boot.class.path=C:\Program Files\Java\jre6\lib\resources.jar;C:\Program Files\Java\jre6\lib\rt.jar;C:\Program Files\Java\jre6\lib\jsse.jar;C:\Program Files\Java\jre6\lib\jce.jar;C:\Program Files\Java\jre6\lib\charsets.jar;C:\Program Files\Java\jre6\lib\ext\dnsns.jar;C:\Program Files\Java\jre6\lib\ext\localedata.jar;C:\Program Files\Java\jre6\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jre6\lib\ext\sunmscapi.jar;C:\Program Files\Java\jre6\lib\ext\sunpkcs11.jar
46??? java.vendor=Sun Microsystems Inc.
47??? file.separator=\
48??? java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi
49??? sun.io.unicode.encoding=UnicodeLittle
50??? sun.cpu.endian=little
51??? sun.desktop=windows
52??? sun.cpu.isalist=pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86
*******获得Java支持编码集合:*********
1??? Big5
2??? Big5-HKSCS
3??? EUC-JP
4??? EUC-KR
5??? GB18030
6??? GB2312
7??? GBK
8??? IBM-Thai
9??? IBM00858
10??? IBM01140
11??? IBM01141
12??? IBM01142
13??? IBM01143
14??? IBM01144
15??? IBM01145
16??? IBM01146
17??? IBM01147
18??? IBM01148
19??? IBM01149
20??? IBM037
21??? IBM1026
22??? IBM1047
23??? IBM273
24??? IBM277
25??? IBM278
26??? IBM280
27??? IBM284
28??? IBM285
29??? IBM297
30??? IBM420
31??? IBM424
32??? IBM437
33??? IBM500
34??? IBM775
35??? IBM850
36??? IBM852
37??? IBM855
38??? IBM857
39??? IBM860
40??? IBM861
41??? IBM862
42??? IBM863
43??? IBM864
44??? IBM865
45??? IBM866
46??? IBM868
47??? IBM869
48??? IBM870
49??? IBM871
50??? IBM918
51??? ISO-2022-CN
52??? ISO-2022-JP
53??? ISO-2022-JP-2
54??? ISO-2022-KR
55??? ISO-8859-1
56??? ISO-8859-13
57??? ISO-8859-15
58??? ISO-8859-2
59??? ISO-8859-3
60??? ISO-8859-4
61??? ISO-8859-5
62??? ISO-8859-6
63??? ISO-8859-7
64??? ISO-8859-8
65??? ISO-8859-9
66??? JIS_X0201
67??? JIS_X0212-1990
68??? KOI8-R
69??? KOI8-U
70??? Shift_JIS
71??? TIS-620
72??? US-ASCII
73??? UTF-16
74??? UTF-16BE
75??? UTF-16LE
76??? UTF-32
77??? UTF-32BE
78??? UTF-32LE
79??? UTF-8
80??? windows-1250
81??? windows-1251
82??? windows-1252
83??? windows-1253
84??? windows-1254
85??? windows-1255
86??? windows-1256
87??? windows-1257
88??? windows-1258
89??? windows-31j
90??? x-Big5-Solaris
91??? x-euc-jp-linux
92??? x-EUC-TW
93??? x-eucJP-Open
94??? x-IBM1006
95??? x-IBM1025
96??? x-IBM1046
97??? x-IBM1097
98??? x-IBM1098
99??? x-IBM1112
100??? x-IBM1122
101??? x-IBM1123
102??? x-IBM1124
103??? x-IBM1381
104??? x-IBM1383
105??? x-IBM33722
106??? x-IBM737
107??? x-IBM834
108??? x-IBM856
109??? x-IBM874
110??? x-IBM875
111??? x-IBM921
112??? x-IBM922
113??? x-IBM930
114??? x-IBM933
115??? x-IBM935
116??? x-IBM937
117??? x-IBM939
118??? x-IBM942
119??? x-IBM942C
120??? x-IBM943
121??? x-IBM943C
122??? x-IBM948
123??? x-IBM949
124??? x-IBM949C
125??? x-IBM950
126??? x-IBM964
127??? x-IBM970
128??? x-ISCII91
129??? x-ISO-2022-CN-CNS
130??? x-ISO-2022-CN-GB
131??? x-iso-8859-11
132??? x-JIS0208
133??? x-JISAutoDetect
134??? x-Johab
135??? x-MacArabic
136??? x-MacCentralEurope
137??? x-MacCroatian
138??? x-MacCyrillic
139??? x-MacDingbat
140??? x-MacGreek
141??? x-MacHebrew
142??? x-MacIceland
143??? x-MacRoman
144??? x-MacRomania
145??? x-MacSymbol
146??? x-MacThai
147??? x-MacTurkish
148??? x-MacUkraine
149??? x-MS932_0213
150??? x-MS950-HKSCS
151??? x-mswin-936
152??? x-PCK
153??? x-SJIS_0213
154??? x-UTF-16LE-BOM
155??? X-UTF-32BE-BOM
156??? X-UTF-32LE-BOM
157??? x-windows-50220
158??? x-windows-50221
159??? x-windows-874
160??? x-windows-949
161??? x-windows-950
162??? x-windows-iso2022jp

*******获获得系统默认编码:*********
name=GBK,displayName=GBK
系统默认语言:zh??? 中国??? CN
--------------1----------------
JP??? 日本
ja??? 日文
JPN
日文 (日本)
???
--------------2----------------
PE??? 秘鲁
es??? 西班牙文
PER
西班牙文 (秘鲁)
???
--------------3----------------
???
en??? 英文

英文
???
--------------4----------------
JP??? 日本
ja??? 日文
JPN
日文 (日本,JP)
JP??? JP
--------------5----------------
PA??? 巴拿马
es??? 西班牙文
PAN
西班牙文 (巴拿马)
???
--------------6----------------
BA??? 波斯尼亚和黑山共和国
sr??? 塞尔维亚文
BIH
塞尔维亚文 (波斯尼亚和黑山共和国)
???
--------------7----------------
???
mk??? 马其顿文

马其顿文
???
--------------8----------------
GT??? 危地马拉
es??? 西班牙文
GTM
西班牙文 (危地马拉)

还有好长,就不继续贴下去了。

上一篇: 什么是多态 下一篇: Hibernate search
发表评论
用户名: 匿名