tags:

views:

4250

answers:

2

hi, I am having an db file in res/raw/folder iam calling Resources.openRawResource() with the file name as R.raw.FileName and i get an input stream but i having an another db file in device i want to copy the contents of that db to the device db i am using BufferedInputStream bi = new BufferedInputStream(is); and FileOutPutStream but i get an exception that database file is corrupted ...any hints how to proceed further . i read the file using File and FileInputStream and the path as /res/raw/fileName ... but that also doesnt works ... Thnx in advance

+1  A: 

hi, my first question is that Resources.openRawResource() works for db file or not becoz everywhere the example are provided for textfile i desperately need it any help would be appreciated ...... or any links to related problem which will help me out to find a answer to the question .....

Sam97305421562
+4  A: 

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.

InputStream ins = getResources().openRawResource(R.raw.my_db_file);

int size = ins.available();

// Read the entire resource into a local byte buffer.
byte[] buffer = new byte[size];
ins.read(buffer);
ins.close();

A copy of your file should now exist in buffer, so you can use a FileOutputStream to save the buffer to a new file.

FileOutputStream fos = new FileOutputStream("mycopy.db");
fos.write(buffer);
fos.close();
Reto Meier
Thnx a ton .... Reto it worked :-)
Sam97305421562
No problem! Accept the answer and we're even :)
Reto Meier