Reputation: 8058
I am in middle of a project where I am storing files in internal storage as follows:
try {
FileWriter file = new FileWriter("/data/data/" + context.getPackageName() + "/" + filename);
file.write(stringData);
file.flush();
file.close();
} catch (IOException e) {
e.printStackTrace();
}
After creating the file I can able to delete the file by its name which I am giving when I am creating it as follows:
File f = new File("/data/data/" + context.getPackageName() + "/" + fileName);
f.delete();
That all is done and working.
My problem is I want to get all the files which are stored in the internal storage without specifying the name of the files.
Note: I can get the file by specifying the name one by one.
But can I get all the files from internal storage or delete all of them directly without specifying each filename.
Upvotes: 2
Views: 1097
Reputation: 367
You can get File objects for all files in the directory like this:
File f = new File("/data/data/" + context.getPackageName());
File[] files = f.listFiles();
for (File fInDir : files) {
fInDir.delete();
}
See http://developer.android.com/reference/java/io/File.html#listFiles()
Upvotes: 1