2016-08-02 62 views
0

因此,我已經構建了一些代碼來下載可以正常工作的文件,並且已將它設置爲下載到工作的應用程序目錄中。它存儲在應用程序文件夾/ files/dltestAndroid應用程序文件路徑

我的問題是與編程檢查是否文件存在,我試過方法之一stackoverflow和由於某種原因,我只能讓我的硬編碼路徑工作。

/sdcard/Android/Data/com.test.alihassan.download/files/dltest/REQS.pdf 

使用內置的方法來檢索路徑給我相同的路徑,但與/數據/數據/ COM ....這不起作用

+0

嘗試'String path = c.getFilesDir()。toString()+「/ files/dltest/REQS.pdf」;'你錯過了....../files/..'部分。它現在工作嗎? –

+0

不能,日誌顯示獲取/data/data/com.test.alihassan.download/files/files/dltest/REQS.pdf –

+0

下載後可以記錄確切的文件路徑嗎?就像下載後立即登錄 –

回答

1
File mydir = context.getFilesDir(); 
File fileWithinMyDir = new File(mydir, "myfile/path/fileNmae"); 
if(fileWithinMyDir.exists()){ 
    //exists 
    }else{ 
    //not exists 
} 

更新:

 //File mydir = this.getFilesDir(); 
     File mydir = this.getExternalFilesDir("/dltest/REQS.pdf"); 
     if (mydir.exists()) { 
      //exists 
     } else { 
      //not exists 
     } 
+0

它看起來像正確的路徑,但不起作用 –

+0

@AliHassan當您下載代碼時顯示,以便我們能夠確定您的正確路徑嗎? –

+0

request.setDestinationInExternalFilesDir(getApplicationContext(),「/ dltest」,「REQS.pdf」); DownloadManager manager =(DownloadManager)getSystemService(Context.DOWNLOAD_SERVICE); manager.enqueue(request);} –

相關問題