Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何下载Android应用程序的sqlite数据库?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在我的 Android应用程序中使用sqlite数据库.我想将数据库下载到pc.任何人都可以告诉我该怎么做?

解决方法

如果您的应用程序在模拟器中,您只需使用DDMS并打开/data/data/your.package.name/databases.

如果您的移动应用程序.这是我将数据库复制到sdcard根文件夹的方法.

/** The name of the database file */
    static final String DATABASE_NAME = "mydatabase.db";
    static final String DATABASE_NAME_FULL = "/data/data/com.my.application/databases/" + DATABASE_NAME;

    public static Boolean BACkupdataBase(Context context){
    Boolean result = true;

    // source path in the application database folder
    String appDbPath = DATABASE_NAME_FULL;

    // DesTination Path to the sdcard app folder
    String sdFolder =  Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + DATABASE_NAME;


    InputStream myInput = null;
    OutputStream myOutput = null;
    try {
        //Open your local db as the input stream
        myInput = new FileInputStream(appDbPath);
        //Open the empty db as the output stream
        myOutput = new FiLeoutputStream(sdFolder);

        //transfer bytes from the inputfile to the outputfile
        byte[] buffer = new byte[1024];
        int length;
        while ((length = myInput.read(buffer))>0){
            myOutput.write(buffer,length);
        }
    } catch (IOException E) {
        result = false;
        e.printStackTrace();
    } finally {
        try {
            //Close the streams
            if(myOutput!=null){
                myOutput.flush();
                myOutput.close();
            }
            if(myInput!=null){
                myInput.close();
            }
        } catch (IOException E) { } 
    }

    return result;
}

你需要在manifest.xml中使用它

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

大佬总结

以上是大佬教程为你收集整理的如何下载Android应用程序的sqlite数据库?全部内容,希望文章能够帮你解决如何下载Android应用程序的sqlite数据库?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。