0

I can read from a csv file in the assets folder, using opencsv. However, writing to the file was a bit more mysterious.

I do the following to open up a file in the /assets folder for reading:

CSVReader reader = new CSVReader(new InputStreamReader(getAssets().open("shoppinglists.csv")));

How do I open the file for writing, and how to I do the writing? Using getAssets() for accessing the file seams clean, so I'd like to use it for reading also.

1
  • Sorry.. You can't. As android .apk file structure is Read-Only.. Better to use Application's Internal Storage or External Storage. Commented Aug 17, 2012 at 12:27

2 Answers 2

1

You probably can't write to the asset file as it is part of the APK.

If I were you, I would copy the asset file into your temp directory and write to that copy as required.

Sign up to request clarification or add additional context in comments.

2 Comments

Ah, crap. I suspected that. But this is a file that's going to live with the application, so temo folder is a bad idea. Where is a good idea to keep a "database" file for the application?
In the data directory, see the Context class
0

Assets folder is present in the packaged apk. It is read only. So you cannot write to it.

1 Comment

You can use Context.getDir to get the directory where you can store your files. Or if it is temporary you could call Context.getCacheDir

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.