开发者

Database storage and retrieval

I want to store my database file in drawable folder and then create its back up in SD-Card. While trying to do this i am findind problem in what path to be given for drawable folder. I am doing this:

try {

        File sd = Environment.getExternalStorageDirectory();

        File data = Environment.getDataDirectory();

        if (sd.canWrite()) {
            //db = openOrCreateDatabase("demodatabase.sqlite",SQLiteDatabase.CREATE_IF_NECESSARY,null);
    currentDBPath = "//drawable//demodatabase.sqlite";



   db=openOrCreateDatabase(uri.toString(), 0, null);
        System.out.println("====="+ currentDBPath);
        backupDBPath = "{demodatabase.sqlite}";

        File currentDB = new File(data,  currentDBPath);

        File backupDB = new File(sd, backupDBPath);

        if (currentDB.exists()) {

        FileChannel src = new FileInputStream(currentDB).getChannel();

        FileChannel dst = new FileOutputStream(backupDB).getChannel();

        dst.transferFrom(src, 0, src.size());

        src.close();

        dst.close();

        }

        } }catch (Exception e) {}
开发者_如何学JAVA

Thanx in advance.


you would put such files not in the drawable folder but in your assets folder and you can get an input stream to these files just by using

context.getAssets().open("demodatabase.sqlite")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜