• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to delete a file after XML Parsing has thrown an error in java?

 
Ranch Hand
Posts: 68
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



i can't delete the file if it contains errors. Problem occurs only in windows platform. Under Linux, the code works correctly. please suggest a solution
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It could be because the file is not closed.  Try using an InputStream object with the parse method.  An InputStream has a close() method.
 
Ranch Hand
Posts: 529
19
Eclipse IDE MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nidheesh Krishna wrote:

I think it has to be Make sure you have xml file in given filePath. To delete if parsing error occurs then you better catch exception in catch clause and write code to delete that xml file like you have in finally but any how that xml file is going to be deleted if exists whether exception occurs or not because it is in finally which is executed although exception occur or not.
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's a good point, actually.
The above code will delete (or attempt to anyway) the file whether there's an error or not.
Which begs the question of how it works on Linux?
 
Nidheesh Krishna
Ranch Hand
Posts: 68
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hai Ganish, its a mistake from my side while posting the question. Actually it is not the problem. deletion problem  occurs only in windows.
 
Nidheesh Krishna
Ranch Hand
Posts: 68
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hai Norm Radder,
I tried Inputstream also.




delete operation still not working on windows
 
Nidheesh Krishna
Ranch Hand
Posts: 68
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i tried debugging of this java codes. delete statement is executing . But deletion does not occurs
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
delete() returns a boolean which tells you whether it was successful or not.
Note that that API doc mentions that the Files.delete() method throws an exception, which might give more details than you would get from the File.delete() one.

I would recommend giving that a go to see why it is failing.
 
You didn't tell me he was so big. Unlike this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic