如何检查内部存储中文件是否可用 [英] how to check if file is available in internal storage

查看:103
本文介绍了如何检查内部存储中文件是否可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Internet下载文件,但下载成功,但是现在
我想检查内部存储中是否存在该文件。

I am trying to download a file from the internet and it succeeded but now I want to check if the file exists in the internal storage.

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);

检索到的项目下载到/ mnt / sdcard / Download。
如何使用代码检查文件是否存在?

The items retrieved are downloaded to /mnt/sdcard/Download. How do I check if the file exists or not using code?

推荐答案

我们说以下是您文件的路径

Let's say following is your file's 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
}

这篇关于如何检查内部存储中文件是否可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆