Java File Path Delete deleteFile(String path)

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

Description

delete File

License

Apache License

Declaration

public static void deleteFile(String path) 

Method Source Code

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

import java.io.*;

public class Main {

    public static void deleteFile(String path) {
        File file = new File(path);
        if (!file.exists()) {
            return;
        }//from   www . j  av a  2 s .com
        if (!file.isDirectory()) {
            if (file.isFile()) {
                file.delete();
            }
            return;
        }
        String[] tempList = file.list();
        String childFilePath = null;
        for (int i = 0; i < tempList.length; i++) {
            if (path.endsWith(File.separator)) {
                childFilePath = path + tempList[i];
            } else {
                childFilePath = path + File.separator + tempList[i];
            }
            File temp = new File(childFilePath);
            if (temp.isFile()) {
                temp.delete();
            } else if (temp.isDirectory()) {
                deleteFile(childFilePath);
            }
        }
        file.delete();
    }
}

Related

  1. deleteFile(String filePathName)
  2. deleteFile(String p_filePath, boolean pb_recursive)
  3. deleteFile(String path)
  4. deleteFile(String path)
  5. deleteFile(String path)
  6. deleteFile(String path)
  7. deleteFile(String path)
  8. deleteFile(String path)
  9. deleteFile(String path)