今天使用android 解析json 文件的时候,一直报个错误:
01-11 05:10:15.727: WARN/System.err(10896):
java.lang.IllegalArgumentException:
File //mnt//sdcard//json.txt contains a path separator:


错误开始前的代码:
try{
FileInputStream fis = this.openFileInput("/mnt/sdcard/json.txt");
//文件中没有数据
if (fis.available() == 0) {
return;
}
byte[] readBytes = new byte[fis.available()];
while (fis.read(readBytes) != -1) {
}




}catch(Exception e){
e.printStackTrace();
}
}

调试后的:

File file = new File("/mnt/sdcard/json.txt");
if (file.exists()) {
FileInputStream fis;
try {
fis = new FileInputStream(file);
fis.available();
byte[] readBytes = new byte[fis.available()];

while (fis.read(readBytes) != -1) {

}
String userData = new String(readBytes);
show.setText(userData);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

注意:
1.FileInputStream 与 openFileInput
2.注意加权限

更多相关文章

  1. 一款常用的 Squid 日志分析工具
  2. GitHub 标星 8K+!一款开源替代 ls 的工具你值得拥有!
  3. RHEL 6 下 DHCP+TFTP+FTP+PXE+Kickstart 实现无人值守安装
  4. Linux 环境下实战 Rsync 备份工具及配置 rsync+inotify 实时同步
  5. android选择图片或拍照图片上传到服务器(包括上传参数)
  6. Android(安卓)App程序结构
  7. Android常见的几种RuntimeException
  8. android6.0编译失败
  9. Android初学者—listView用法

随机推荐

  1. android 保存bitmap到SD卡
  2. android添加联系人(直接添加到联系人数据
  3. Android(安卓)FragmentTabHost轻松实现微
  4. android 2.2 apidemos 赏析笔记 5
  5. Android(安卓)Circular Progress Button
  6. android 4.0 HttpURLConnection. getInpu
  7. android 遍历控件
  8. android 判断字符串是否是数字
  9. Android(安卓)xml定义常量
  10. android nfc(官方翻译)