我试图删除位于路径的文件
/storage/714D-160A/Xender/image/Screenshot_commando.png
Run Code Online (Sandbox Code Playgroud)
到目前为止我做了什么:
try{
String d_path = "/storage/714D-160A/Xender/image/Screenshot_commando.png";
File file = new File(d_path);
file.delete();
}catch(Exception e){
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
并且文件仍在其位置(未删除:()
我也在Manifest文件中获得了许可.
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.STORAGE" />
Run Code Online (Sandbox Code Playgroud) 我的应用程序下载并解压缩特定文件夹中的文件:
output = new FileOutputStream(realpath, true);
output.write(buffer, 0, bytesRead);
ZipFile zipFile = new ZipFile(realpath);
Run Code Online (Sandbox Code Playgroud)
随着新推出的ACTION_OPEN_DOCUMENT_TREEIntent,我想让用户选择该文件夹.
当测试我收到的值时onActivityResult,我会得到一个类似Path的路径/tree/primary:mynewfolder,这不是物理真实的路径/sdcard/mynewfolder.
Uri treeUri = data.getData();
String sPath = treeUri.getPath();
Log.v("Path from Tree ", sPath);
Run Code Online (Sandbox Code Playgroud)
我的解压方法需要真正的路径:
ZipFile zipFile = new ZipFile(realpath);
Run Code Online (Sandbox Code Playgroud)
如何/sdcard/mynewfolder从Lollipop(API 21和22)中提供的URI 获得真实路径?
我正在使用外部SD卡的PersistableUriPermission并将其存储以供进一步使用.现在我希望当用户向我提供文件路径时,从我的应用程序中的文件列表中,我想编辑文档并重命名它.
所以我有要编辑的文件的文件路径.
我的问题是如何从我的TreeUri获取该文件的Uri以及编辑文件.