Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android saving file to cache directory

I am trying to do something simple like save a file to a cache directory in Android and I am having a lot of problems. I am using Simple serializer to write out my file into xml.

Here is my code:

public void testWrite(ListDefinitions ld)
{
    Serializer serializer = new Persister();

    String fileName = "sampleExport.xml";
    try {
        File file = new File(mContext.getCacheDir(), fileName);
        file.createNewFile();
        serializer.write(ld, file);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

And I keep getting the following error:

09-18 00:35:06.229: W/System.err(4442): java.io.FileNotFoundException: /data/data/com.main/cache/sampleExport.xml: open failed: EISDIR (Is a directory)

Thank you for the help.

like image 803
AlexIIP Avatar asked Feb 03 '26 22:02

AlexIIP


1 Answers

Probably you created directory before with wrong call. Try to clean app data in settings.

like image 57
vovkab Avatar answered Feb 06 '26 10:02

vovkab



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!