`

android java.lang.IllegalArgumentException contains a path separator

阅读更多
今天使用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.注意加权限
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics