Following the tutorial here I've been trying to copy this and I keep getting errors on the Outputstream declaration line.
My following code is here:
private void copyDataBase() throws IOException{
System.out.println("copyDatabase Start");
//Open your local db as the input stream
InputStream myInput = myContext.getAssets().open(DB_NAME);
System.out.println("copyDatabase: InputStream Set");
// Path to the just created empty db
String outFileName = "/data/data/com.example.sqllitedb_user/databases/";
System.out.println("copyDatabase: outFileName:" + outFileName);
//Open the empty db as the output stream
OutputStream myOutput = new FileOutputStream(outFileName);
System.out.println("copyDatabase: FileOutputStream set to above name");
//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);
}
System.out.println("copyDatabase: byte buffer thing ran" );
//Close the streams
myOutput.flush();
myOutput.close();
myInput.close();
System.out.println("copy Database complete");
}
I see some other people have had the same problems and I was wondering what the solution is.
Is there another (easier) way to import and access my own sqlite table?
IGNORE THIS POST - Turns out I forgot to call the initialisation method on my main activity.