I have a database file in res/raw/
folder. I am calling Resources.openRawResource()
with the file name as R.raw.FileName
and I get an input stream, but I have an another database file in device, so to copy the contents of that db to the device db I use:
BufferedInputStream bi = new BufferedInputStream(is);
and FileOutputStream, but I get an exception that database file is corrupted. How can I proceed?
I try to read the file using File
and FileInputStream
and the path as /res/raw/fileName
, but that also doesn't work.
Best Solution
Yes, you should be able to use
openRawResource
to copy a binary across from your raw resource folder to the device.Based on the example code in the API demos (content/ReadAsset), you should be able to use a variation of the following code snippet to read the db file data.
A copy of your file should now exist in
buffer
, so you can use aFileOutputStream
to save the buffer to a new file.