Java Delete File deleteFile(String dest)

Here you can find the source of deleteFile(String dest)

Description

delete File

License

Open Source License

Declaration

public static void deleteFile(String dest) throws IOException 

Method Source Code


//package com.java2s;
import java.io.File;

import java.io.FileNotFoundException;

import java.io.IOException;

public class Main {
    private static final String MSG_NOT_FOUND = "Not found: ";
    private static final String MSG_NOT_A_FILE = "Not a file: ";
    private static final String MSG_UNABLE_TO_DELETE = "Unable to delete: ";

    public static void deleteFile(String dest) throws IOException {
        deleteFile(new File(dest));
    }//from  w w  w  .java  2 s .  c om

    public static void deleteFile(File dest) throws IOException {
        if (!dest.exists()) {
            throw new FileNotFoundException(MSG_NOT_FOUND + dest);
        }
        if (!dest.isFile()) {
            throw new IOException(MSG_NOT_A_FILE + dest);
        }
        if (!dest.delete()) {
            throw new IOException(MSG_UNABLE_TO_DELETE + dest);
        }
    }
}

Related

  1. deleteFile(final File file)
  2. deleteFile(final File file)
  3. deleteFile(final String dirname)
  4. deleteFile(Object fileObj)
  5. deleteFile(String archiveFilename)
  6. deleteFile(String f)
  7. deleteFile(String file)
  8. deleteFile(String file)
  9. deleteFile(String file)