• 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
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Not able to delete xml files after reading

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

I am unzipping xml files from a zip file using java util and reading xml files using DOM parser through my application after reading I want to delete the files which I unzipped. But until unless I wont close my application I cant delete the files. Even I tried to delete from Windows Explorer but it is showing message like It is being used by another person or program. ........

How can I delete those files with out closing the application.

My code is:
try {

DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setNamespaceAware(true);
DocumentBuilder builder;
try {
builder = domFactory.newDocumentBuilder();
File fileDirectory = new File(fileDir);
String files[] = fileDirectory.list();
Document doc;
doc = builder.parse(fileDir+fileName);
doc.getDocumentElement ().normalize ();
String rootNode = doc.getDocumentElement().getNodeName();
NodeList bookslist = doc.getElementsByTagName(rootNode);
String servername = (String) ((Element) bookslist.item(0)).getElementsByTagName("servername").item(0).getChildNodes().item(0).getNodeValue();
String theatername = (String) ((Element) bookslist.item(0)).getElementsByTagName("theatername").item(0).getChildNodes().item(0).getNodeValue();
} catch (Exception e) {
e.printStackTrace();
}

Please guide me.

Thanking you.

--raaja. g
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I would investigate using the Zip library to get an InputStream and parse that Stream rather than extracting to a temp file.

Bill
 
Marshal
Posts: 27214
87
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's because your application hasn't closed the file. (The parser should close the file but apparently it doesn't.)

So pass a FileInputStream to the parser, instead of a File, and close it yourself after you have finished parsing.
 
Raaja Gotluru
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks for the reply. I created a FileInputStream and parsed and closed it after use. But still I am not able to delete.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please use code blocks while posting code. You can do that by using the "Code" button in the message editor window.


What does the deleteDir method look like (the name of the method doesn't sound right, since you are passing it a file and not just a directory)? Also please post the exact exception stacktrace that you receive. While posting that stacktrace, wrap it in a code block too.
 
Raaja Gotluru
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

deleteDir is a common method used to delete files or directories. Which I found in some examples site.

The code is like:

 
Raaja Gotluru
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I got it. I didnt closed the stream after zipping the file.

Thanks.
 
She'll be back. I'm just gonna wait here. With this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic