Java File Path Delete delFileIfExists(String path)

Here you can find the source of delFileIfExists(String path)

Description

del File If Exists

License

Apache License

Declaration

public static void delFileIfExists(String path) throws IOException 

Method Source Code

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

import java.io.File;

import java.io.IOException;

public class Main {
    public static void delFileIfExists(String path) throws IOException {
        File f = new File(path);
        if (f.exists()) {
            delFile(f);//ww  w.j  av  a  2 s  .  c om
        }

    }

    public static boolean delFile(File file) throws IOException {
        try {
            file.delete();
            return true;
        } catch (Exception e) {
            throw new IOException("Failed to delete the file:" + file.getAbsoluteFile(), e);
        }
    }
}

Related

  1. delFile(String filePathAndName)
  2. delFile(String filePathAndName)
  3. DelFile(String in_Path, ArrayList arrFileList)
  4. delFile(String path)
  5. delFile(String pathName)
  6. delFiles(String path)
  7. delTree(String path)