我正在尝试将文件下载到目录,该目录可能会根据用户选择的目录而有所不同。我将当前目录存储在文件对象中,现在尝试下载该文件。文件已下载,但未下载指定目录。那么,我该怎么做才能获取所选目录中的文件。
// Getting path to store the file
String path = root.getAbsolutePath();
path += curr.getName();
request.setDestinationInExternalPublicDir(path, new File(url).getName());
// get download service and enqueue file
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
Run Code Online (Sandbox Code Playgroud)
传递给 File 构造函数的名为 url 的字符串包含一个 URL。只需使用它来检索文件的名称即可。
更新:我刚刚找到该文件。是在手机里,不是在sd卡里。它位于此文件夹中,storage\emulated\00。不知道为什么?另外,我得到的绝对路径是 storage\emulated\0。