howto copy a large file from /res/raw to /data/data/PACKAGE/databases

  • Replies:6
mcfly
  • Forum posts: 286

Aug 8, 2010, 3:08:56 PM via Website

Hi All,

I tried the solution described on http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/ , which explains how to deploy a preloaded sqlite db with your app.
It works fine with small files, but my 1.5 MB sqlite.db can't be copied. ( with 125 kb it works ) . With 1.5 MB i get an ioexception.

Is there a filesize restriction in the filesystem of android ?

Is there a solution for copying large files ?

My code for this:
private void testcopyDataBase() {

//Open your local db as the input stream
InputStream myInput = this.getResources().openRawResource(R.raw.mydb);

// Path to the just created empty db
String outFileName = "/data/data/PACKAGE/databases/history10.db";

//Open the empty db as the output stream
OutputStream myOutput;
try {
myOutput = new FileOutputStream(outFileName);
//transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
//Close the streams
myOutput.flush();
myOutput.close();
myInput.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

Reply
Jeremiah
  • Forum posts: 775

Aug 8, 2010, 11:24:11 PM via Website

Which line are you getting the IOException on?
Also are you doing this while the menu or a ui is waiting on it? It could be timing out the ui, in which case you'll need to put the method into a thread.
http://developer.android.com/guide/appendix/faq/commontasks.html#threading

— modified on Aug 8, 2010, 11:35:46 PM

Reply
mcfly
  • Forum posts: 286

Aug 9, 2010, 9:02:48 PM via App

i get the error on the read line. no gui. simple read. as mentoined , if the file as smaller i can read it. i see that in bug mode eclipse.

Reply
Jeremiah
  • Forum posts: 775

Aug 10, 2010, 6:42:38 AM via Website

I found a post that says that the max filesize for raw and assets, is about 1mb, but he also posted a solution. http://www.mail-archive.com/android-developers@googlegroups.com/msg28194.html


The @ symbol messes up the link, copy and paste the whole link in your address bar.

— modified on Aug 10, 2010, 6:43:41 AM

Reply
mcfly
  • Forum posts: 286

Aug 11, 2010, 9:16:50 PM via App

thank you.

Reply
Rommy Saiko
  • Forum posts: 1

May 12, 2011, 6:00:49 AM via Website

okay, I've read the tutorial, but I'm still confused about one thing..
where should I put the database?? should I put it in the folder named assets or /res/raw???
because I read in that tutorial, it's said that we must put it in asset folder.
After I tried it and ran it, I got force close...

So, what's the solution????
Need help please....

Reply
Ashish Sahu
  • Forum posts: 1

Oct 26, 2012, 2:12:45 PM via Website

hi frnd i need your help
i want to copy from res/raw to android/data/obb
so please help me how could i do this please reply full and correct code and tell me which files i need to modify
i dont good in codes

Reply