@H_502_1@是否有一个函数来获取文件路径的目录部分?
所以从
String a="/root/sdcard/Pictures/img0001.jpg";
你得到
"/root/sdcard/Pictures"
解决方法
是.首先,构建一个表示图像路径的
File
:
File file = new File(a);
如果您从相对路径开始:
file = new File(file.getAbsolutePath());
那么,get the parent:
String dir = file.getParent();
或者,如果要将目录作为File对象,
File dirAsFile = file.getParentFile();