get Root directory (i.e external or external sdcard) from file path

徘徊边缘 提交于 2019-12-12 03:04:15

问题


I am facing a situation to calculate the free size of the currently selected primary memory(i.e external or external sdcard). All i have is the file path in app specific folder like below

"/root/extsdcard/Android/data/com.a.b/files/img0001.jpg";

or

"/root/ext/Android/data/com.a.b/files/img0001.jpg";

How i can get the path "/root/extsdcard/" or "/root/ext/" respectively from above shown paths?


回答1:


Just mention "/" for root directory e.g. File

File f=new File("/");

String files[]=   f.list(); 


来源:https://stackoverflow.com/questions/38381871/get-root-directory-i-e-external-or-external-sdcard-from-file-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!