Reputation: 143
i have a database on my webspace. Now i want to download this database and copy it into my /databases folder. It copies some parts of the DB but i can not access it. With "Root Explorer" it says "Error - An error occured while opening the database. unable to open the database file"
private final static String DB_NAME = "werweisswasquiz";
private final static String DB_PATH = "data/data/my-package-name/databases/";
try {
// Log.d(TAG, "downloading database");
URL url = new URL("http://unnediger.bplaced.net/Files/mydbfile");
URLConnection ucon = url.openConnection();
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(1024);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
/* Convert the Bytes read to a String. */
OutputStream myOutput = new FileOutputStream(DB_PATH+DB_NAME);
myOutput.write(baf.toByteArray());
myOutput.flush();
myOutput.close();
bis.close();
is.close();
} catch (Exception e) {
Log.e("DOWNLOAD", "downloadDatabase Error: ", e);
return false;
}
Upvotes: 2
Views: 2170
Reputation: 143
So i finally found the solution by myself.
The server thought that the file "mydbfile" is a txt file so i added the extention ".db" for sqlite database. now it works perfectly.
Upvotes: 7