How to check if a file is available in internal memory

I try to download a file from the Internet, and it succeeded, but now I want to check if the file exists in the internal memory.

else if (arg0.getId() == R.id.btn_download) { Toast.makeText(this, "download button clicked", Toast.LENGTH_SHORT).show(); DownloadManager.Request request = new DownloadManager.Request(Uri.parse(names[b])); request.setDescription("Downloading.."); request.setTitle("Futsing Magazine Issue " + (this.mPictureManager.getCurrentIndex() +1) ); // in order for this if to run, you must use the android 3.2 to compile your app if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { request.allowScanningByMediaScanner(); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); } request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "Futsing Magazine Issue " + (this.mPictureManager.getCurrentIndex() +1) +".pdf"); // get download service and enqueue file DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); manager.enqueue(request); 

The resulting items are uploaded to / mnt / sdcard / Download. How to check if a file exists or not code?

+5
source share
2 answers

Say the next file path

 String path=context.getFilesDir().getAbsolutePath()+"/filename"; File file = new File ( path ); if ( file.exists() ) { // Toast File is exists } else { // Toast File is not exists } 
+13
source
 File applictionFile = new File(Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_DOWNLOADS)+ "/"+<file-name>); if(applictionFile != null && applictionFile.exists()){ } 

if the file is uploaded to the default donwload directory

+5
source

Source: https://habr.com/ru/post/1443764/


All Articles