943,640 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1951
  • Java RSS
Mar 13th, 2009
0

Why doesn't this code delete a file? Help me troubleshoot

Expand Post »
Java Syntax (Toggle Plain Text)
  1.  
  2.  
  3. String deleteString = e.getPath();
  4. File deleteListFile = new File(deleteString);
  5.  
  6.  
  7. deleteListFile.delete();
so to talk you through it, the File object is obtained by the results by system.out.println (not shown here)

...and then I am getting the path of the file by using getpath()

then i want that file path and its file deleted, but wen i go check in that folder its not deleted.

The list of files mathcing the criteria are listed correctly because they get displayed, just not deleted..

Help??
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
caps_lock is offline Offline
43 posts
since Nov 2008
Mar 13th, 2009
-1

Re: Why doesn't this code delete a file? Help me troubleshoot

come on please!
Reputation Points: 10
Solved Threads: 0
Light Poster
caps_lock is offline Offline
43 posts
since Nov 2008
Mar 13th, 2009
0

Re: Why doesn't this code delete a file? Help me troubleshoot

Is this File object a directory? If so it must be empty to be deleted. The only other thing I can think of if this is not a directory is that maybe your issue has to do with file permissions?

EDIT: And don't get impatient, we will help as soon as we can!
Last edited by darkagn; Mar 13th, 2009 at 12:09 pm.
Reputation Points: 395
Solved Threads: 192
Veteran Poster
darkagn is offline Offline
1,136 posts
since Aug 2007
Mar 13th, 2009
0

Re: Why doesn't this code delete a file? Help me troubleshoot

hmm nope, ive set up if statements not to inlcude direcories, i just added a system.out.println to states that the deletion process is in progess but that message doesnt even show up, im just going to have fun with trial and errror
Reputation Points: 10
Solved Threads: 0
Light Poster
caps_lock is offline Offline
43 posts
since Nov 2008
Mar 13th, 2009
0

Re: Why doesn't this code delete a file? Help me troubleshoot

This means your program is getting stuck up at some place, so there may be some exception causing this. Put a try-catch block and print a stack trace in the catch clause, you will soon know what happens.
Reputation Points: 485
Solved Threads: 89
Posting Shark
verruckt24 is offline Offline
944 posts
since Nov 2008
Mar 13th, 2009
0

Re: Why doesn't this code delete a file? Help me troubleshoot

hi thanks for the reply

i changed it to abosulte path instead but tha tdidnt have an effect so i changed it back, then I checked if the objects existed by using .exists() and getting that printed out by the system, and the results were true

i mananged to get the message up to so i dont think its gettting stuck now, but the files are still not getting deleted. and there not system files just images.
Reputation Points: 10
Solved Threads: 0
Light Poster
caps_lock is offline Offline
43 posts
since Nov 2008
Mar 13th, 2009
0

Re: Why doesn't this code delete a file? Help me troubleshoot

But you are still missing two points here. One, that you aren't still catching any exceptions that might occur during such an operation. Only taking the SOP statement up will not work, rather it won't cause any difference. Second, What do you think the program will do if you do not have permission over the files you are deleting, it's going to throw an exception which you are ignoring altogether.
Reputation Points: 485
Solved Threads: 89
Posting Shark
verruckt24 is offline Offline
944 posts
since Nov 2008
Mar 13th, 2009
0

Re: Why doesn't this code delete a file? Help me troubleshoot

lol i will add the try and catch if it works, im testing it in a small direcotry first, ive had no exceptions yet, but i will add try and catch it works with even an exception

just some more info:

the system.out.println gets its information form an input stream, and there is more than one file to delete
Reputation Points: 10
Solved Threads: 0
Light Poster
caps_lock is offline Offline
43 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Enumerating permutations
Next Thread in Java Forum Timeline: The better Java book?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC