public void copyDbToInternalFolder() throws IOException {
String DB_PATH = Environment.getDataDirectory().getPath()+getPackageName()+"/Databases/"; // Don't worry I know this line doesn't work, however, nothing was working
String DB_NAME = "Client_Responses.db";
InputStream myInput = context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS,"Client_Responses.db"); //needs to get database file from Downloads folder
String outFileName = DB_PATH + DB_NAME;
OutputStream myOutput = new FileOutputStream(outFileName);
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
myOutput.flush();
myOutput.close();
myInput.close();
}
I have written several related apps that create sqlite database files in the devices Downloads folder. I need to stick to this method in order to support all the way back to first generation tablets. API 8 in essence.
Now, the manager needs to import found files from the Downloads folder and import them to its own database folder.
The above code doesn't work, null pointer exceptions and incorrect filename/pathname create errors and the app will force quit, and I have tried what seems like everything. My thinking is now bottlenecked.
I have been struggling with this and would welcome input.
Note: I will most likely duplicate the code in different class files, each copying a differing database name.