mcfly
- Forum posts: 286
Aug 8, 2010, 3:08:56 PM via Website
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();
}
}
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();
}
}
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.