• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Unable to Delete Folder + I can't belive i m posting this :(

 
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,

I have a simple program for which will create one folder,
copy some file from another folder to the newly created folder,
compress the newly created folder and delete the newly created folder which had been compressed.

My program is creating new folder compressing it, but not able to delete it.



and if i hard code the path like bellow and put it on the top of the main method it deletes the folder. fine.

same line if i move to the end of the method it does not delete folder.

What could be the possible reason for it. i m not able to understand it.

 
Marshal
Posts: 74354
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't know, but it doesn't look like a beginner's topic. The IO forum looks a good place to move it, because they discuss files there.
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't ever actually close the files you're reading from. You set "in" to null, but you don't ever call in.close(). On Windows, an open file cannot be deleted. I also don't see your deleteDir() routine, but hopefully it deletes all the files in a folder before deleting the folder, as Windows, again, won't delete a folder with files in it.
 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand what mistake i am making.

deleteDir() is there in the main method at second last line and in a classs it is last method.

bellow is my modified compressFolder() method.



Now i am closing the in and out both the stream.

the deleteDir() is recursively called.. The unit test for the deleteDir() metho dis pass.

Something is wrong in the compressFolder() method. After execution of compressFolder() method deleteDir() method does not delete folder.

With this new compressFolder() method in which i am taking care of closing all the streams, its deleting only one file from the folder.

logically it should delete all the files one by one and then it should delete the folder.

bellow is the stack trace

 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
finally i got it.

i was calling in.close() in finally block that means it was closing only last file.

Bellow is the method which is closing all the streams properly.


Thanks a lot all of you.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic