Android Directory Create createDirectory(String directory, String subDirectory)

Here you can find the source of createDirectory(String directory, String subDirectory)

Description

create Directory

Declaration

private static void createDirectory(String directory,
            String subDirectory) 

Method Source Code

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

public class Main {
    private static void createDirectory(String directory,
            String subDirectory) {
        String dir[];//from w  ww .  j  a  v  a  2s  . com
        File fl = new File(directory);
        try {
            if (subDirectory == "" && fl.exists() != true)
                fl.mkdir();
            else if (subDirectory != "") {
                dir = subDirectory.replace('\\', '/').split("/");
                for (int i = 0; i < dir.length; i++) {
                    File subFile = new File(directory + File.separator
                            + dir[i]);
                    if (subFile.exists() == false)
                        subFile.mkdir();
                    directory += File.separator + dir[i];
                }
            }
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
    }
}

Related

  1. mkdir(String path)
  2. mkdir(String s)
  3. mkdirs(String pathName)
  4. mkdirs(String pathName)
  5. createDir(String path, String folder)