public String hebGetExternalRootDir(String externalAndriodSubDirPath){ if ( externalAndriodSubDirPath.isEmpty()){ File file = getActivity().getExternalFilesDir(null); externalAndriodSubDirPath = file.toString(); file = null; } if (externalAndriodSubDirPath.contains("/Android")) { return externalAndriodSubDirPath.split("/Android")[0]; } return ""; } public File hebCreateFile(String filePath) { int index = filePath.lastIndexOf("/"); if (index>0) { String dir = filePath.substring(0, filePath.lastIndexOf("/")); File dirInfo = new File(dir); if (false == dirInfo.exists()) { Boolean bOK = dirInfo.mkdirs(); if (false == bOK) { dirInfo = null; return null; } } dirInfo = null; } return new File(filePath); }
完。
原文:https://www.cnblogs.com/liyou-blog/p/12058307.html