方法一:
java.nio.charset.Charset.defaultCharset();
方法二:
package com.wxg.util;
import java.security.Provider;
import java.security.Security;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;
public class Test {
public void testOne(){
Provider[] providers = Security.getProviders();
for(int i=0; i<providers.length; i++){
Provider p = providers[i];
System.out.println("getName : " + p.getName() + ", getInfo : " + p.getInfo());
}
}
public void testTwo(){
Properties pros = System.getProperties();
/*Enumeration enumeration = pros.propertyNames();
while(enumeration.hasMoreElements()){
System.out.println(enumeration.nextElement());
}*/
Set<String> sets = pros.stringPropertyNames();
Iterator<String> it = sets.iterator();
int num = 1;
while(it.hasNext()){
System.out.println(num + " : " + it.next());
num++;
}
}
public void testThree(){
Properties pro = System.getProperties();
String[] pNames = new String[]{"file.encoding.pkg",
"user.country",
"sun.jnu.encoding",
"file.encoding",
"user.language",
"sun.io.unicode.encoding"};
for(int i=0; i<pNames.length; i++){
System.out.println((i+1) + " : " + pNames[i] + " = " + pro.getProperty(pNames[i]));
}
}
public static void main(String[] args) {
Test t = new Test();
t.testOne();
t.testTwo();
t.testThree();
}
}
--
output:
getName : SUN, getInfo : SUN (DSA key/parameter generation; DSA signing; SHA-1, MD5 digests; SecureRandom; X.509 certificates; JKS keystore; PKIX CertPathValidator; PKIX CertPathBuilder; LDAP, Collection CertStores, JavaPolicy Policy; JavaLoginConfig Configuration)
getName : SunRsaSign, getInfo : Sun RSA signature provider
getName : SunJSSE, getInfo : Sun JSSE provider(PKCS12, SunX509 key/trust factories, SSLv3, TLSv1)
getName : SunJCE, getInfo : SunJCE Provider (implements RSA, DES, Triple DES, AES, Blowfish, ARCFOUR, RC2, PBE, Diffie-Hellman, HMAC)
getName : SunJGSS, getInfo : Sun (Kerberos v5, SPNEGO)
getName : SunSASL, getInfo : Sun SASL provider(implements client mechanisms for: DIGEST-MD5, GSSAPI, EXTERNAL, PLAIN, CRAM-MD5; server mechanisms for: DIGEST-MD5, GSSAPI, CRAM-MD5)
getName : XMLDSig, getInfo : XMLDSig (DOM XMLSignatureFactory; DOM KeyInfoFactory)
getName : SunPCSC, getInfo : Sun PC/SC provider
getName : SunMSCAPI, getInfo : Sun's Microsoft Crypto API provider
1 : java.runtime.name
2 : sun.boot.library.path
3 : java.vm.version
4 : java.vm.vendor
5 : java.vendor.url
6 : path.separator
7 : java.vm.name
8 : file.encoding.pkg
9 : user.country
10 : sun.java.launcher
11 : sun.os.patch.level
12 : java.vm.specification.name
13 : user.dir
14 : java.runtime.version
15 : java.awt.graphicsenv
16 : java.endorsed.dirs
17 : os.arch
18 : java.io.tmpdir
19 : line.separator
20 : java.vm.specification.vendor
21 : user.variant
22 : os.name
23 : sun.jnu.encoding
24 : java.library.path
25 : java.specification.name
26 : java.class.version
27 : sun.management.compiler
28 : os.version
29 : user.home
30 : user.timezone
31 : java.awt.printerjob
32 : file.encoding
33 : java.specification.version
34 : user.name
35 : java.class.path
36 : java.vm.specification.version
37 : sun.arch.data.model
38 : java.home
39 : sun.java.command
40 : java.specification.vendor
41 : user.language
42 : awt.toolkit
43 : java.vm.info
44 : java.version
45 : java.ext.dirs
46 : sun.boot.class.path
47 : java.vendor
48 : file.separator
49 : java.vendor.url.bug
50 : sun.cpu.endian
51 : sun.io.unicode.encoding
52 : sun.desktop
53 : sun.cpu.isalist
1 : file.encoding.pkg = sun.io
2 : user.country = CN
3 : sun.jnu.encoding = GBK
4 : file.encoding = GBK
5 : user.language = zh
6 : sun.io.unicode.encoding = UnicodeLittle