2012年4月7日 星期六

String的getBytes()

原來沒指定引數是使用OS的CodePage去Encoding
我們又沒有在log4j設定檔設定log編碼,怪不得我們的LOG沒辦法顯示難字
log4j的設定檔可以在append區塊加入encoding為UTF-8
用Notepad++打開LOG時編碼要選UTF-8

p.s.1.
可以使用-Dfile.encoding=UTF8設定JVM的encoding
可以使用Charset.defaultCharset()去取得JVM的charset

p.s.2.作業系統查看Code Page指令:
Linux:locale
Windows:chcp

ref:
http://www.360doc.com/content/08/1015/09/61497_1765862.shtml

http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#getBytes%28%29

public byte[] getBytes()
Encodes this String into a sequence of bytes using the platform's default charset, storing the result into a new byte array.



The behavior of this method when this string cannot be encoded in the default charset is unspecified. The CharsetEncoder class should be used when more control over the encoding process is required.



Returns:

The resultant byte array

Since:

JDK1.1

沒有留言:

張貼留言