Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * @(#)IOUtils.java
 *
 * $Date: 2012-07-03 01:10:05 -0500 (Tue, 03 Jul 2012) $
 *
 * Copyright (c) 2011 by Jeremy Wood.
 * All rights reserved.
 *
 * The copyright of this software is owned by Jeremy Wood. 
 * You may not use, copy or modify this software, except in  
 * accordance with the license agreement you entered into with  
 * Jeremy Wood. For details see accompanying license terms.
 * 
 * This software is probably, but not necessarily, discussed here:
 * http://javagraphics.java.net/
 * 
 * That site should also contain the most recent official version
 * of this software.  (See the SVN repository for more details.)
 */

import java.io.File;

public class Main {
    /** Empty this directory.
     * @return true if the delete was successful.
     */
    public static boolean empty(File file) {
        if (file.isDirectory() == false) {
            return false;
        }
        boolean success = true;
        File[] children = file.listFiles();
        for (int a = 0; a < children.length; a++) {
            if (delete(children[a]) == false)
                success = false;
        }
        return success;
    }

    /** Delete this file and all its children, if any.
     * @return true if the delete was successful.
     */
    public static boolean delete(File file) {
        boolean success = true;
        if (file.isDirectory()) {
            File[] children = file.listFiles();
            for (int a = 0; a < children.length; a++) {
                if (delete(children[a]) == false)
                    success = false;
            }
        }
        if (file.delete() == false)
            success = false;
        return success;
    }
}