我正在尝试获取以下内部路径:“ / storage / emulated / 0 / Android / data / br.com.d_apps.detonajogos / files / Download / 1.txt”,以检查文件是否为(1.txt )存在,但我找不到用Environment来获取它的方法。
我以此下载文件:
downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
Uri uri = Uri.parse(url);
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setDestinationInExternalFilesDir(this, Environment.DIRECTORY_DOWNLOADS, "1.txt");
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
并尝试使用以下方法检查文件:
File extStore = (Environment.getExternalStorageDirectory());
File pdf = new File(extStore.getAbsolutePath() + "1.txt");
if(pdf.exists()){
Toast.makeText(this, "exists", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(this, "does not exist", Toast.LENGTH_SHORT).show();
}
答案 0 :(得分:0)
Environment
无法访问您要访问的内容。尝试使用getExternalFilesDir()
类中的Context
,它会为您提供内部应用程序的外部文件目录,然后将/Download/1.txt
添加到该路径。