Android Folder Create forceFolderExist(String folder)

Here you can find the source of forceFolderExist(String folder)

Description

Create folder if it's not exist

Parameter

Parameter Description
folder folder to create if it does not exist

Exception

Parameter Description
IOException an exception

Declaration

// //////////////////////////////////////////////////////
public static void forceFolderExist(String folder) throws IOException 

Method Source Code

//package com.java2s;
import java.io.*;

public class Main {
    /**/*from   w  w  w.  j  a v a  2s  .  c om*/
     * Create folder if it's not exist
     * 
     * @param folder
     *            folder to create if it does not exist
     * @throws IOException
     * @author Thai Hoang Hiep
     */
    // //////////////////////////////////////////////////////
    public static void forceFolderExist(String folder) throws IOException {
        File flTemp = new File(folder);
        if (!flTemp.exists()) {
            if (!flTemp.mkdirs())
                throw new IOException("Could not create folder " + folder);
        } else if (!flTemp.isDirectory())
            throw new IOException("A file with name" + folder
                    + " already exist");
    }
}

Related

  1. createPath(String folderName, String fileName)
  2. makeParent(File file)
  3. makeParent(String file)
  4. getFolderInTarget(String folderName)