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 {
    static public boolean deleteDirectory(File path) {
        if (path == null)
            return false;
        if (path.exists()) {
            File[] files = path.listFiles();
            if (files == null) {
                return true;
            }
            for (int i = 0; i < files.length; i++) {
                if (files[i].isDirectory()) {
                    deleteDirectory(files[i]);
                } else {
                    files[i].delete();
                }
            }
        }
        return (path.delete());
    }

    public static boolean delete(String path) {
        if (path == null || path.isEmpty())
            return false;
        File f = new File(path);
        if (f.exists()) {
            if (f.isDirectory()) {
                return deleteDirectory(f);
            } else {
                return f.delete();
            }
        }
        return false;
    }
}