(1) URLEncoder.encode()输入什么字符集?
@Deprecated
public static String encode(String s)
调用这行代码:encode(s, dfltEncName);
dfltEncName = AccessController.doPrivileged(
new GetPropertyAction("file.encoding")
);
输出来以后得到utf-8
(2)String.getBytes()使用的什么字符集?
public byte[] getBytes()
使用的字符集是:Charset.defaultCharset().name();
输出来得到utf-8
另外,java中同一个字符串根据不同的字符集得到byte数是不一样的。
如:
System.out.println("中".getBytes().length); 输出3
System.out.println("中1".getBytes("utf-8").length); 输出4
System.out.println("中1".getBytes("gbk").length); 输出3
@Deprecated
public static String encode(String s)
调用这行代码:encode(s, dfltEncName);
dfltEncName = AccessController.doPrivileged(
new GetPropertyAction("file.encoding")
);
输出来以后得到utf-8
(2)String.getBytes()使用的什么字符集?
public byte[] getBytes()
使用的字符集是:Charset.defaultCharset().name();
输出来得到utf-8
另外,java中同一个字符串根据不同的字符集得到byte数是不一样的。
如:
System.out.println("中".getBytes().length); 输出3
System.out.println("中1".getBytes("utf-8").length); 输出4
System.out.println("中1".getBytes("gbk").length); 输出3