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;

import java.io.File;

public class Main {

    public static void deleteFile(String fileName) {
        File f = new File(fileName);
        if (!f.exists())
            throw new IllegalArgumentException("Delete: no such file or directory: " + fileName);
        if (!f.canWrite())
            throw new IllegalArgumentException("Delete: write protected: " + fileName);
        if (f.isDirectory()) {
            String[] files = f.list();
            if (files.length > 0)
                throw new IllegalArgumentException("Delete: directory not empty: " + fileName);
        }//  w ww  .j  a  va 2 s  .c om
        boolean success = f.delete();
        if (!success)
            throw new IllegalArgumentException("Delete: deletion failed");
    }
}

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)