Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.File;

public class Main {
    public static boolean deleteDirectory(File directory) throws Exception {
        try {
            if (directory.exists()) {
                File[] files = directory.listFiles();
                for (int i = 0; i < files.length; i++)
                    if (files[i].isDirectory())
                        deleteDirectory(files[i]);
                    else
                        files[i].delete();
            }
        } catch (Exception e) {
            throw new Exception(new StringBuilder().append("Error occurred while trying to delete directory ")
                    .append(directory).toString());
        }
        return directory.delete();
    }
}