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

Reply

Join Date: Nov 2008
Posts: 37
Reputation: caps_lock is an unknown quantity at this point 
Solved Threads: 0
caps_lock caps_lock is offline Offline
Light Poster

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

 
0
  #1
Mar 13th, 2009
  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??
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 37
Reputation: caps_lock is an unknown quantity at this point 
Solved Threads: 0
caps_lock caps_lock is offline Offline
Light Poster

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

 
-1
  #2
Mar 13th, 2009
come on please!
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 793
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 110
darkagn's Avatar
darkagn darkagn is offline Offline
Master Poster

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

 
0
  #3
Mar 13th, 2009
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.
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 37
Reputation: caps_lock is an unknown quantity at this point 
Solved Threads: 0
caps_lock caps_lock is offline Offline
Light Poster

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

 
0
  #4
Mar 13th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 823
Reputation: verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough 
Solved Threads: 73
verruckt24's Avatar
verruckt24 verruckt24 is offline Offline
Practically a Posting Shark

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

 
0
  #5
Mar 13th, 2009
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.
Get up every morning and take a look at the Forbes' list of richest people. If your name doesn't appear.... GET TO WORK !!!
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 37
Reputation: caps_lock is an unknown quantity at this point 
Solved Threads: 0
caps_lock caps_lock is offline Offline
Light Poster

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

 
0
  #6
Mar 13th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 823
Reputation: verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough 
Solved Threads: 73
verruckt24's Avatar
verruckt24 verruckt24 is offline Offline
Practically a Posting Shark

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

 
0
  #7
Mar 13th, 2009
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.
Get up every morning and take a look at the Forbes' list of richest people. If your name doesn't appear.... GET TO WORK !!!
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 37
Reputation: caps_lock is an unknown quantity at this point 
Solved Threads: 0
caps_lock caps_lock is offline Offline
Light Poster

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

 
0
  #8
Mar 13th, 2009
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC