Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Mozilla Public License 

import android.content.Context;

import android.content.res.Resources;

import java.io.File;
import java.io.IOException;

public class Main {
    public static final String FAIL_CREATE_DIRECTORY = "Create directory %s failed.";

    /**
     * Make directories. If directory exists, do nothing.
     *
     * @param context
     * @param path
     *          directory path to create.
     * @throws java.io.IOException
     *           if directory doesn't exist and fail to create.
     */
    public static void mkdirs(Context context, String path) throws IOException {
        Resources res = context.getResources();
        File pathFile = new File(path);
        if (!pathFile.exists()) {
            if (!pathFile.mkdirs()) {
                throw new IOException(String.format(FAIL_CREATE_DIRECTORY, pathFile.getAbsolutePath()));
            }
        }
    }
}