Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.io.File;

import java.io.IOException;

public class Main {
    public static boolean createFile(String filepath, boolean recursion) throws IOException {
        return createFile(new File(filepath), recursion);
    }

    public static boolean createFile(File file, boolean recursion) throws IOException {
        boolean result = false;
        if (!file.exists()) {
            try {
                result = file.createNewFile();
            } catch (IOException e) {
                if (!recursion) {
                    throw e;
                }
                File parent = file.getParentFile();
                if (!parent.exists())
                    parent.mkdirs();
                try {
                    result = file.createNewFile();
                } catch (IOException e1) {
                    throw e1;
                }
            }
        }
        return result;
    }
}