Java Delete File deleteFile(File file)

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

Description

delete File

License

Apache License

Declaration

public static int deleteFile(File file) 

Method Source Code


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

import java.io.*;

public class Main {

    public static int deleteFile(File file) {
        if (file == null) {
            return -1;
        }//from  ww  w  .java 2s .c o  m
        if (file.exists()) {
            if (file.isFile()) {
                if (file.delete()) {
                    return 0;
                }
            }
            if (file.isDirectory()) {
                File[] subFiles = file.listFiles();
                if (subFiles != null) {
                    for (File subFile : subFiles) {
                        deleteFile(subFile);
                    }
                }
                if (file.delete()) {
                    return 0;
                }
            }
            return -1;
        } else {
            return -1;
        }
    }
}

Related

  1. deleteFile(File file)
  2. deleteFile(File file)
  3. deleteFile(File file)
  4. deleteFile(File file)