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()) {
file.delete();
} 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.
Greetings people ! Nice page you have here!