https://openhome.cc/Gossip/Encoding/JVMEncoding.html
有些 API 若不指定編碼,通常會使用 JVM 預設編碼,預設會與作業系統預設編碼相同,像是 String
建構式、 getBytes()
方法或這邊看到的 FileReader
等(其他還有 java.io
、java.util
、java.net
等套件中的一些 API),可以使用 Charset.defaultCharset()
取得預設編碼。
在啟動 JVM 時,其實可以使用 -Dfile.encoding 指定 JVM 預設編碼,例如:
C:\workspace>java -Dfile.encoding=UTF-8 cc.openhome.Main
getBytes() encodes a String into a byte array using the platform's default charset
https://www.baeldung.com/string/get-bytes
https://openhome.cc/Gossip/Encoding/String.html
ref:
https://openhome.cc/Gossip/Encoding/index.html
https://www.javaworld.com.tw/jute/post/view?bid=21&id=282136&tpg=1&ppg=1&sty=1&age=0#282136
https://stackoverflow.com/questions/12659417/why-does-javas-string-getbytes-uses-iso-8859-1
https://docs.oracle.com/javase/tutorial/i18n/text/string.html
沒有留言:
張貼留言