본문 바로가기

안드로이드 개발/개발팁

폴더 생성및 삭제

폴더생성 및 폴더삭제

 

 

 

    public static File makeDirectory(String dir_path) {
        File dir = new File(dir_path);
        if (!dir.exists()) {
            dir.mkdirs();
        }
        return dir;
    }

 

 

 

 

 

public static int deleteDir(String path) {
        File file = new File(path);
        if (file.exists()) {
            File[] childFileList = file.listFiles();
            for (File childFile : childFileList) {
                if (childFile.isDirectory()) {
                    deleteDir(childFile.getAbsolutePath());
                } else {
                    childFile.delete();
                }
            }
            file.delete();
            return 1;
        } else {
            return 0;
        }
    }