Here you can find the source of deleteFile(String filepath, JFrame parent)
Parameter | Description |
---|---|
filepath | - path of file to delete |
parent | - parent component |
public static boolean deleteFile(String filepath, JFrame parent)
//package com.java2s; //License from project: Open Source License import javax.swing.*; import java.io.*; public class Main { /**/*from ww w . ja v a 2s .co m*/ * Deletes the given file * @param filepath - path of file to delete * @param parent - parent component * @return boolean */ public static boolean deleteFile(String filepath, JFrame parent) { File tempFile = new File(filepath); File trashFile = new File(ClassLoader.getSystemResource("trash") .getPath(), new File(filepath).getName()); if (trashFile.exists()) recursiveDeleteFile(trashFile); if (tempFile.exists() && !tempFile.renameTo(trashFile)) { String errstr = "Unable to delete module.. Please check if trash path exists..."; JOptionPane.showMessageDialog(parent, errstr, "File Delete Error", JOptionPane.ERROR_MESSAGE); return false; } else return true; } public static void recursiveDeleteFile(File f) { File[] children = f.listFiles(); if (children != null) { for (int i = 0; i < children.length; i++) recursiveDeleteFile(children[i]); } f.delete(); } }