Why not to delete a file after creating this file with java io api?
<p>I created a file and add some contents into it. Then, I want to delete it with java api. Before this operation, the write out stream is closed, but still failed, so could someone help me to resolve it?</p>

<p>Code snippets:</p>

<pre><code>private static void _saveLogFile(String logContent, String urlPathName) throws Exception {

 try {

   StringBuilder sb = new StringBuilder("");
   sb.append(logContent + "\r\n");
   String a = sb.toString();            
   BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
        new FileOutputStream(urlPathName, true))); 
    bw.write(a);
    bw.close();
 } catch (FileNotFoundException e) {         
   e.printStackTrace();
 }
}

private static void _deleteLogFile(String urlPathName) throws Exception {


    File file = new File(urlPathName);
    if (!file.exists()) {
        throw new IllegalArgumentException("Delete: no such file or directory: " + urlPathName);
    }

    if (file.isDirectory()) {
        String[] files = file.list();
        if (files.length &gt; 0) {
            throw new IllegalArgumentException("Delete: directory is not empty: " + urlPathName);
        }
    }

    boolean success = file.delete();
    if (!success) {
        throw new IllegalArgumentException("Delete:deletion failed.");
    }
}
</code></pre>
