gpt4 book ai didi

android - 如何检查文件是否在内部存储中可用

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:53:33 24 4
gpt4 key购买 nike

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

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。如何使用代码检查文件是否存在?

最佳答案

假设以下是您的文件路径

String path=context.getFilesDir().getAbsolutePath()+"/filename";
File file = new File ( path );

if ( file.exists() )
{
// Toast File is exists
}
else
{
// Toast File is not exists
}

关于android - 如何检查文件是否在内部存储中可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13205385/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com