Java File Path Delete deleteFile(String strPath, String fileName)

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

Description

delete File

License

Apache License

Declaration

public static final boolean deleteFile(String strPath, String fileName) 

Method Source Code


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

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static final boolean deleteFile(String strPath, String fileName) {
        File file = findIt(strPath, fileName);
        if (file != null) {
            return file.delete();
        }//w  w w .  java  2  s  .co m
        return false;
    }

    public static final File findIt(String strPath, String fileName) {
        File rootDir = new File(strPath);
        File[] files = rootDir.listFiles();
        List<File> directories = new ArrayList<File>(files.length);
        for (File file : files) {
            if (file.getName().equals(fileName)) {
                return file;
            } else if (file.isDirectory()) {
                directories.add(file);
            }
        }
        for (File directory : directories) {
            File file = findIt(directory.getAbsolutePath(), fileName);
            if (file != null) {
                return file;
            }
        }

        return null;
    }
}

Related

  1. deleteFile(String path)
  2. deleteFile(String path)
  3. deleteFile(String path, String filename)
  4. deleteFile(String strFolderPath, String strFileName)
  5. deleteFile(String strPath)
  6. DeleteFileFolder(String path)
  7. deleteFileFromDisk(String name, String path)
  8. deleteFileIfExists(String path)
  9. deleteFileOrDirectory(String path)