Android,使用FileInputStream从SDC读取文件,报空指针错误
当我尝试从 SDCard 中的文件中读取某些内容时,我使用了 FileInputStream 类,代码如下: 代码:
文件路径=“/sdcard/myfile/testFile” FileInputStream fileIn = null;
文件输入 = 新 文件输入流(文件路径);字节 [] InBuf = 新字节[1024];
fileIn.read(InBuf);施特鲁布格 文件内容 = new String(InBuf);
fileIn.close();
当我运行我的程序时,android在我的最后一行不断报告空指针错误:“fileIn.close”,我真的不知道原因
I used FileInputStream class when I was trying to read something from my files reside in SDCard, the codes are as follows:
Code:
filepath = "/sdcard/myfile/testFile"
FileInputStream fileIn = null;
fileIn = new
FileInputStream(filepath); byte []
InBuf = new byte[1024];
fileIn.read(InBuf); Strubg
fileContent = new String(InBuf);
fileIn.close();
when I ran my program, android keep reporting null pointer error on my last line:"fileIn.close", I really didn't know the reason
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像这样使用它:
您一定缺少扩展名。
Use it like this:
You must be missing the extension.
昨晚我工作到很晚,终于成功了,虽然我不确定这是否是确切的原因。我只是尝试了以下方法,然后没有再出现空指针报告,
无论如何,非常感谢您的帮助。 ^^
I worked till late last night, finally, I make it work, though I am not sure if it is exact reason. I simply tried the following methods, then no more null pointer report came,
Any way, thank you so much for your help. ^^