我的网站空间上有一个数据库。现在我想下载这个数据库并将其复制到我的 /databases 文件夹中。它复制了数据库的某些部分,但我无法访问它。使用“根资源管理器”显示“错误 - 打开数据库时发生错误。无法打开数据库文件”
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;
}