2013-11-29 137 views
13

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

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

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

    } 
+0

http://stackoverflow.com/questions/17546718/android-getting-internal-storage-absolute-path 指该链接...... –

回答

29

你可以使用这条线时,使用Context.getFilesDir()方法来获得内部存储

编辑

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

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

+0

你能请简要回答呢? – Aarushi

+0

@Aarushi现在检查 – d3m0li5h3r

+0

它可以在我的手机中找到 –

9

String dir = getFilesDir().getAbsolutePath();

0
getFileStreamPath(String name) of Context. 

返回在其中一个文件

openFileOutput(String, int) 

存储创建文件系统的绝对路径。

相关问题