2013-11-29 77 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) 

存儲創建文件系統的絕對路徑。

相關問題