【问题标题】:How to get file path of file from internal storage in android如何从android的内部存储中获取文件的文件路径
【发布时间】:2013-11-29 07:13:34
【问题描述】:

在我们的应用程序中,我们将 pdf 文件存储到内部存储中。现在我想获取它的文件路径并需要存储到数据库中。请告诉我如何获取它的文件路径。 下面的代码:

public void storeIntoInternalMem(byte[] databytes, String name) {
        try
        {
            FileOutputStream fileOuputStream = openFileOutput(name, MODE_PRIVATE);
            fileOuputStream.write(databytes);
            fileOuputStream.close();

        } catch (IOException e)
        {
            e.printStackTrace();
        }

    }

【问题讨论】:

标签: android


【解决方案1】:

您可以使用Context.getFilesDir()方法获取内部存储的路径

编辑

当使用FileOutputStream fileOuputStream = openFileOutput(name, MODE_PRIVATE);这一行时,内部存储路径由openFileOutput()方法的默认实现获得。在该位置创建一个具有指定名称的新文件。现在,当您想获取同一个文件的路径时,可以使用getFilesDir() 来获取创建该文件的目录的绝对路径。你可以这样做:-

File file = new File(getFilesDir() + "/" + name);

【讨论】:

  • 你能简单回答一下吗?
  • 在我的手机哪里可以找到
【解决方案2】:

String dir = getFilesDir().getAbsolutePath();

【讨论】:

    【解决方案3】:
     getFileStreamPath(String name) of Context.
    

    返回使用

    创建文件的文件系统上的绝对路径
    openFileOutput(String, int) 
    

    已存储。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-02
      • 2020-09-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多