Java File Path Delete deletefile(String delpath)

Here you can find the source of deletefile(String delpath)

Description

deletefile

License

Open Source License

Declaration

public static boolean deletefile(String delpath) throws FileNotFoundException, IOException 

Method Source Code

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

import java.io.File;
import java.io.FileNotFoundException;

import java.io.IOException;

public class Main {
    public static boolean deletefile(String delpath) throws FileNotFoundException, IOException {
        try {/*  w w  w  . j  a  v  a2s  .c  om*/
            File file = new File(delpath);
            if (!file.isDirectory()) {
                file.delete();
            } else if (file.isDirectory()) {
                String[] filelist = file.list();
                for (int i = 0; i < filelist.length; i++) {
                    File delfile = new File(delpath + "/" + filelist[i]);
                    if (!delfile.isDirectory()) {
                        delfile.delete();
                    } else if (delfile.isDirectory()) {
                        deletefile(delpath + "" + filelist[i]);
                    }
                }
                file.delete();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return true;
    }
}

Related

  1. deleteFile(File path)
  2. deleteFile(File path)
  3. deleteFile(final String dirPath, final String fileName)
  4. deleteFile(final String filePathName)
  5. DeleteFile(String _filePath)
  6. deleteFile(String filePath)
  7. deleteFile(String filePath)
  8. deleteFile(String filePath)
  9. deleteFile(String filePath)