android中TextView显示中文发生乱码的问题

来源:互联网 发布:mac艺术字体下载大全 编辑:程序博客网 时间:2024/05/22 18:22
许多文件的中文码制是 GBK(GB2312)格式,而ANDROID用的UNICODE格式,要转换一下,就行了。看我的:TextView textView21;//----------------------------------------    private String readStream(InputStream is)    {    // 资源流(GBK汉字码)变为串      String res;      try      {            byte[] buf = new byte[is.available()];                     is.read(buf);            res = new String(buf,"GBK");     //  这里就是转换的关键!!!            is.close();      } catch (Exception e)      {         res="";        }       return(res);        } //---------------------------------------    try      {     String f1="test.txt";    InputStream   iS=getAssets().open(f1);    txt=readStream(iS);   textView21.setText(txt);     }  catch(Exception  e)   {}
0 0