许多文件的中文码制是 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)
{
}
android中TextView显示中文发生乱码的问题
最新推荐文章于 2026-05-21 07:38:23 发布
本文介绍了一种在Android环境中将GBK编码的文本文件转换为Unicode编码的方法。通过使用特定的Java代码片段,可以读取GBK编码的文件并将其内容转换为Unicode格式,以便在Android应用中正确显示。

4629

被折叠的 条评论
为什么被折叠?



