Can't delete JSON file

Hello,

I've been reading about file deletion and I am aware that you need to call close() on a stream before deleting it. However I cannot call close() on a JSONObject and therefore I cannot delete the .json file by declaring a File object and calling File.delete() (it returns false). I tried setting the JSONObject to null and call System.gc(); before deleting but to no avail.

Tagged:

Answers

  • You can try but I didn't test myself:

    File  f = new File("yourFile.json");
    f.delete();
    
  • edited June 2016

    I did that as well, forgot to mention it. Will edit my post.

  • I have : boolean isDir = f.isDirectory(); if (isDir) { scenes = loadJSONArray("scenes.json"); } else { f.delete(); }

Sign In or Register to comment.