小编and*_*edi的帖子

将数据库从服务器复制到Android

我的网站空间有一个数据库.现在我想下载这个数据库并将其复制到我的/ databases文件夹中.它复制了数据库的某些部分但我无法访问它.使用"Root Explorer"时,它显示"Error - 打开数据库时出错.无法打开数据库文件"

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(); …
Run Code Online (Sandbox Code Playgroud)

database android copy

2
推荐指数
1
解决办法
2002
查看次数

标签 统计

android ×1

copy ×1

database ×1