android系统中*.bin文件读取时乱码问题
阿军 2013-05-02 09:42:41 大家好,我最近想通过程序查看android系统中的*.bin文件里的数据信息,我试过用notepad和ue查看软件打开后看到都是乱码。
后来我想通过android程序来读取查看不知是什么原因看到的也全部是些乱码,我的查看方法如下:
从android系统中复制出*.bin文件放到我项目工程中assets文件中,读取代码如下:
private AssetManager am;
private InputStream is;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
readerBin();
}
private void readerBin() {
am = this.getResources().getAssets();
try {
is = am.open("xtra.bin");
if (is != null) {
Log.e("TAG", "It worked!");
}
String str=readTextFile(is);
Log.e("TAG", str);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private String readTextFile(InputStream inputStream) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte buf[] = new byte[1024];
int len;
try {
while ((len = inputStream.read(buf)) != -1) {
String text = new String(buf, "UTF-8");
Log.i("TAG", text);
outputStream.write(buf, 0, len);
}
outputStream.close();
inputStream.close();
} catch (IOException e) {
}
return outputStream.toString();
}
但最后读取出来的数据也是些乱码,不知道是何原因?请大家帮忙一些。。。