Results 1 to 5 of 5
Thread: Can't Delete A File
- 03-07-2011, 10:16 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 3
- Rep Power
- 0
Can't Delete A File
I used the following codes but i am unable to delete the file. Can anyone help ??
import java.io.File;
public class Delete {
public static void main(String[] args) {
Thread a = new Thread();
a.start();
}
public void run()
{
String fileName = "default\\sample.txt";
// A File object to represent the filename
File f = new File(fileName);
// Make sure the file or directory exists and isn't write protected
if (!f.exists())
throw new IllegalArgumentException(
"Delete: no such file or directory: " + fileName);
if (!f.canWrite())
throw new IllegalArgumentException("Delete: write protected: "
+ fileName);
// If it is a directory, make sure it is empty
if (f.isDirectory()) {
String[] files = f.list();
if (files.length > 0)
throw new IllegalArgumentException(
"Delete: directory not empty: " + fileName);
}
// Attempt to delete it
f.delete();
}
}
Or is there any other way to delete a file using threads ???
- 03-07-2011, 10:46 AM #2
- 03-07-2011, 11:07 AM #3
Member
- Join Date
- Mar 2011
- Posts
- 3
- Rep Power
- 0
Solved
I just need to extend the class to Threads and change the codes as
public class Delete extends Threads
then
Thread a= new Delete();
- 03-07-2011, 11:13 AM #4
- 03-07-2011, 11:16 AM #5
Member
- Join Date
- Mar 2011
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
i want to read xml file from ftpserver and after i also want to delete from ftp
By enggvijaysingh@gmail.com in forum Advanced JavaReplies: 1Last Post: 11-20-2010, 08:05 PM -
Delete A File
By nitinverma in forum CLDC and MIDPReplies: 13Last Post: 06-15-2010, 09:12 AM -
Delete From .txt file
By Sarinam in forum New To JavaReplies: 86Last Post: 06-28-2008, 11:17 AM -
problem when I try to delete a file
By tommy in forum Advanced JavaReplies: 2Last Post: 07-31-2007, 03:44 PM -
How to delete a file
By Alpha in forum New To JavaReplies: 1Last Post: 05-26-2007, 09:11 AM
Bookmarks