Java Delete File deleteFile(String fileName)

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

Description

delete File

License

Open Source License

Declaration

public static void deleteFile(String fileName) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

public class Main {
    public static void deleteFile(String fileName) {
        deleteFile(new File(fileName));
    }/*  w w w.  ja v  a2 s . com*/

    public static void deleteFile(File file) {
        if (file.exists())
            delete(file);
    }

    public static boolean exists(String fileName) {
        return (new File(fileName)).exists();
    }

    private static void delete(File file) {
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            for (File file2 : files)
                delete(file2);
        }
        if (!file.delete())
            throw new RuntimeException("Failed to delete file: " + file);
    }
}

Related

  1. deleteFile(String fileName)
  2. deleteFile(String fileName)
  3. deleteFile(String fileName)
  4. deleteFile(String fileName)
  5. deleteFile(String fileName)
  6. deleteFile(String fileName)
  7. deleteFile(String filename)
  8. deleteFile(String filename)
  9. deleteFile(String FileName)