• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sometime not deleting files

 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

The following code sometime works and sometime not work. Please advise



Best regards
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Under what circumstances it works, and under what it does not?
Are you getting an exception when it doesn't work, and if it is the case can you post the message you get?
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the main problem that I am not having any exception or error message.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, none of these methods is throwing an exception (an oversight by my side, too).
You should try using new Files.delete(Path) (the class introduced in JDK 7). If something fails, you will get appropriate exception so you can know what went wrong. Check this tutorial.
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On a side note, the null check on line 7 is unnecessary as you just created the File object.
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all for assisting me

The real problem was some where else. I mean I not closed the input and output stream that's why the file was not deleted. I properly closed them and it started to work fine

Thanks again & good night
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic