1. 程式人生 > >位元組流 字元流 亂碼

位元組流 字元流 亂碼

位元組流轉字元流有可能出現亂碼問題
在new String 的時候加上需要的編碼格式
InputStream is = StockCache.class.getResourceAsStream(path);
BufferedInputStream bis = new BufferedInputStream(is);
byte[] bytes = new byte[10 * 1024];
int len = -1;
while ((len = bis.read(bytes)) != -1) {
    jsonStr = new String(bytes, 0, len,"UTF-8");//加上編碼格式
}