• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Nidheesh Krishna
Ranch Hand
Posts: 62
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • 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
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • 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.
 
Ganish Patil
Ranch Hand
Posts: 529
19
Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • 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.
 
Dave Tolls
Ranch Foreman
Posts: 3061
37
  • Mark post as helpful
  • send pies
  • 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: 62
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • 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: 62
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai Norm Radder,
I tried Inputstream also.




delete operation still not working on windows
 
Nidheesh Krishna
Ranch Hand
Posts: 62
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried debugging of this java codes. delete statement is executing . But deletion does not occurs
 
Dave Tolls
Ranch Foreman
Posts: 3061
37
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!