创建新文件(包括上级文件夹),获取外置SD卡的根目录

    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);
    }

    public Boolean hebCreateFile2(String filePath) {
        File fd = hebCreateFile(filePath);
        if (null != fd) {
            fd = null;
            return true;
        }
        return false;
    }

完。

原文地址:https://www.cnblogs.com/liyou-blog/p/12058307.html