大家好,我最近想通过程序查看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();
} 但最后读取出来的数据也是些乱码,不知道是何原因?请大家帮忙一些
后来我想通过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();
} 但最后读取出来的数据也是些乱码,不知道是何原因?请大家帮忙一些
解决方案 »
- Android SDK Manager 更新速度极慢
- AsyncTask与Handler+Thread异步更新UI,哪种方式比较好?
- 请教一个windows下用NDK的问题
- intent可以在两个activity之间传递cursor对象么?求助求助求助
- Android老油条请进
- android4.4 编译问题
- 人生路上遇到的纠结问题,戳进来看看,帮我分析下吧。谢谢各位了
- android使用socket向服务器发送图片失败
- 如何修改 Android系统里的/sys/class/net/wlan0/address 文件内容?Java代码应该咋写?谢谢,请大家不吝赐教
- Android的问题
- android activity动画切换效果 真机一闪而过,模拟器正常
- 如何把apk包放进eclipse软件中修改
你的解码必须和编码一致才行。