About Bijoy

Bijoy has written 148 articles so far, you can find them below.

Deleting a file

The source code for deleting a file is shown below.Here I am trying to delete the file if it is not a directory.

import java.io.File;
import java.io.FileReader;

* User: Bijoy
* Date: 6/25/12
* Time: 9:18 PM
public class FileDelete {
public static void main(String[] args) {
try {
File file = new File("E:/temp/test.txt");
if (!file.isDirectory()) {
} else {
System.out.println("It is a directory");
} catch (Exception e) {

Remember, the specified file should be existing. If it is not existing please create the file in the correct path.