0

I have saved some ser file by below code

OutputStream file = context.openFileOutput(fileName, Context.MODE_PRIVATE);


            BufferedOutputStream buffer = new BufferedOutputStream( file );

            ObjectOutput output = new ObjectOutputStream(buffer);

            try{

              output.writeObject(map1);



            }

Now please tell me how to delete all files saved through this code.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Sanchit Paurush
  • 6,114
  • 17
  • 68
  • 107

2 Answers2

3

You can do it like this, Get the Path of folder that you want to delete with all files and then delete all files one by one.

File dir = new File("/data/directory_name/");

if (dir.isDirectory()) {
        String[] children = dir.list();
        for (int i = 0; i < children.length; i++) {
            new File(dir, children[i]).delete();
        }
    }
Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242
1

try this code

File file = new File(Environment.getExternalStorageDirectory()+"/filenameWithExtenstion");
file.delete();
Mohammed Azharuddin Shaikh
  • 41,633
  • 14
  • 96
  • 115
Android
  • 1,417
  • 9
  • 11