Java File Delete delete(File file)

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

Description

Delete a file.

License

BSD License

Parameter

Parameter Description
file The file to delete

Exception

Parameter Description
IOException if file is not null, exists but deletefails.

Declaration

public static void delete(File file) throws IOException 

Method Source Code


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

import java.io.File;
import java.io.IOException;

public class Main {
    /**//from ww w.  ja v a2  s.  co m
     * Delete a file. Unlinke {@link File#delete()}, this throws an
     * exception if deletion fails.
     * @param file The file to delete
     * @throws IOException if file is not null, exists but delete
     *    fails.
     */
    public static void delete(File file) throws IOException {
        if (file == null || !file.exists())
            return;
        if (!file.delete())
            throw new IOException("Unable to delete file " + file.getAbsolutePath());
    }
}

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)