0

I'm trying to run the following code when an android activity is created, so that two files will be deleted.

protected void onCreate(Bundle savedInstanceState) {
    File file = new File (CSQ1.likes_filename);
    file.delete();
    file = new File (CSQ1.answers_filename);
    file.delete();

    // Rest of onCreate function
}

Seems simple enough, but it doesn't work. What am I doing wrong?

user2824889
  • 1,085
  • 5
  • 16
  • 28
  • 2
    How do you know it doesn't work? – Jason C Mar 30 '14 at 23:53
  • 2
    Jason has a valid question. But even if you know it didn't work, what are the paths of the files you are trying to delete? Do you have write access to their parent directories? – Chris Stratton Mar 30 '14 at 23:58
  • The files are still unchanged when I read them. I know I have the permissions because I can read/write them in the same class – user2824889 Mar 31 '14 at 07:18

1 Answers1

0

Have you had a look at this mate?: How to delete from sd-card

Seems you could be missing permission in your manifest file and some basic checking on the file i.e. File.Exists() before you delete wouldn't go a miss.

Community
  • 1
  • 1
Biosonik
  • 43
  • 6