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.
I got it done by giving: