Java File Delete delete(File file)

Here you can find the source of delete(File file)

Description

Deletes a file.

License

Open Source License

Parameter

Parameter Description
file to be deleted

Return

true, if file was successfully deleted or scheduled to be deleted on exit.

Declaration

public static boolean delete(File file) 

Method Source Code

//package com.java2s;
// it under the terms of the GNU General Public License as published by

import java.io.File;

import java.util.logging.Logger;

public class Main {
    /** jdk1.4 logger */
    private static Logger logger = Logger.getLogger("de.axelwernicke.mypod.util");

    /**//from  w w  w .j  ava2s  . co  m
     * Deletes a file.
     * If file can not deleted now, its scheduled to be deleted on myPod exit
     *
     * @param file to be deleted
     * @return true, if file was successfully deleted or scheduled to be deleted on exit.
     */
    public static boolean delete(File file) {
        logger.entering("de.axelwernicke.mypod.util.FileUtils", "delete");

        boolean success = false;

        try {
            if (file.canRead() && file.canWrite()) {
                boolean deleted = file.delete();
                if (!deleted) {
                    file.deleteOnExit();
                }

                success = true;
            }
        } catch (Exception e) {
            logger.warning("Exception raised: " + e.getMessage());
            e.printStackTrace();
        }

        logger.exiting("de.axelwernicke.mypod.util.FileUtils", "delete");

        return success;
    }
}

Related

  1. delete(File file)
  2. delete(File file)
  3. delete(File file)
  4. delete(File file)
  5. delete(File file)
  6. delete(File file)
  7. delete(File file)
  8. delete(File file)
  9. delete(File file)