如何在Android中从手机的内存中读取文件?

如何在Android中从手机的内存中读取文件?,第1张

概述我已经使用android中的FileOutputStream从HttpConnection下载了一个文件,现在它被写在路径中的手机内部存储器中,因为我在文件资源管理器中找到它/data/data/com.example.packagename/files/123.ics现在,我想打开&从手机的内存读取文件内容到UI.我试图通过使用FileInputStream

我已经使用android中的fileOutputStream从httpconnection下载了一个文件,现在它被写在路径中的手机内部存储器中,因为我在文件资源管理器中找到它

/data/data/com.example.packagename/files/123.ics

现在,我想打开&从手机的内存中读取文件内容到UI.我试图通过使用fileinputStream来做到这一点,我已经给出了带扩展名的文件名来打开它,但我不确定如何提及内部存储器中文件的文件路径,因为它强制应用程序关闭.

有什么建议?

这就是我在做的事情:

try{                 fileinputStream fileIn;         fileIn = openfileinput("123.ics");  inputStream in = null;  EditText UserID = (EditText) findVIEwByID(R.ID.user_ID);  byte[] buffer = new byte[1024];  int len = 0;  while ( (len = in.read(buffer)) > 0 )           {          UserID.setText(fileIn.read(buffer, 0, len));  }                      fileIn.close();                       } catch (fileNotFoundException e){   e.printstacktrace();}catch (IOException e){       e.printstacktrace();}

解决方法:

String filePath = context.getfilesDir().get@R_419_4613@Path();//returns current directory.file file = new file(filePath, filename);Similar post here 

read file from phone memory

总结

以上是内存溢出为你收集整理的如何在Android中从手机的内存中读取文件?全部内容,希望文章能够帮你解决如何在Android中从手机的内存中读取文件?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1113906.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存