如何将文件存储在 android 的内部存储中并从 android phone 访问它们

How to store file in Internal storage in android and access them from android phone

如何在 android 的内部存储中存储文件以及如何在 android phone 中访问它们。我在谷歌上搜索了很多,发现我们可以存储文件,但只能通过模拟器访问,或者 phone 必须植根。

无根 phone 的解决方案是什么?

以及如何通过给定路径访问内部存储文件?路径是什么?

请帮忙。提前致谢,我们将不胜感激。

只需使用文件资源管理器应用程序。大多数手机都预装了一个。但是,如果您没有,您可以随时下载您选择的一种。我使用 ES File explorer

从那时起,只需导航到您要访问的文件即可。

希望这能回答您的问题。

您可以通过 FileOutput 流执行此操作:

    String fileName = "file.txt";
    String content = "hello world";

    FileOutputStream outputStream = null;
    try {
       outputStream = openFileOutput(fileName, Context.MODE_PRIVATE);
       outputStream.write(content.getBytes());
       outputStream.close();
} catch (Exception e) {
    e.printStackTrace();
}

注意:此方法只能写入内部存储,MODE_PRIVATE意味着其他应用无法访问您的文件。 您还需要在清单 xml.

中授予 WRITE_EXTRENAL_STORAGE 权限

这会将文件存储在:data/data/app/files/file.txt

要获取存储中保存的文件列表,

File dirFiles = mContext.getFilesDir();
for (String fname: dirFiles.list())
{
   Toast.makeText(mContext,fname,Toast.LENGTH_LONG).show();
}