Question

In my app, I am downloading some files. It gets automatically saved in data/data/project/files folder. Below code is used for that purpose.

URL url = new URL(audioUrl);
URLConnection urlConnection = url.openConnection();  
InputStream inputStream = urlConnection.getInputStream();
byte[] buffer = new byte[inputStream.available()];
FileOutputStream fos = openFileOutput(fileName, Context.MODE_PRIVATE);

int j;
while((j = inputStream.read(buffer))!=-1)
{
    fos.write(buffer, 0, j);
}
fos.close();

What I require is: before adding anything to this folder i want to clear all files if any are present. How can I do that? Please reply. Thanks in advance.

Was it helpful?

Solution

I got it done by giving:

String[] allFiles = fileList();
for(int k = 0 ; k < allFiles.length; k++) {
    deleteFile(allFiles[k]);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top