Here you can find the source of deleteFile(String fileName)
public static void deleteFile(String fileName)
//package com.java2s; import java.io.File; public class Main { public static void deleteFile(String fileName) { File f = new File(fileName); if (!f.exists()) throw new IllegalArgumentException("Delete: no such file or directory: " + fileName); if (!f.canWrite()) throw new IllegalArgumentException("Delete: write protected: " + fileName); if (f.isDirectory()) { String[] files = f.list(); if (files.length > 0) throw new IllegalArgumentException("Delete: directory not empty: " + fileName); }// w ww .j a va 2 s .c om boolean success = f.delete(); if (!success) throw new IllegalArgumentException("Delete: deletion failed"); } }