尝试打开文件 文件存在(并且检查返回true) 但是in.available返回0
如果我用设备监视器查看文件,我可以看到该文件,并且它有一个大小...
if(fileExists(filePath) == false)
return "ERROR";
FileInputStream in = openFileInput(filePath);
if(in.available() <= 0)
{
//THIS ALWAYS HAPPENS!!!
}
InputStreamReader inputStreamReader = new InputStreamReader(in);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
StringBuilder sb = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
sb.append(line);
}
inputStreamReader.close();
权限设置
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_LOGS" />
答案 0 :(得分:0)
openFileInput有什么作用? 应该这样做:
FileInputStream in = new FileInputStream(new File(filePath));