sqlite小型数据库,在开发的时候用于保存数据,在这不做关于它的介绍,本文只是写出了怎么拷贝应用的数据到本地sd卡中。如:一个数据库名为dandy.db的,拷贝到本地中叫seeker.db
代码如下:
/** * 拷贝数据库到sd卡 * * @deprecated <uses-permission android:name="android.permission.write_external_storage"/> */ public static void copydatabasetosd(){ if (!environment.media_mounted.equals(environment.getexternalstoragestate())) { return ; } file dbfile = new file(mvpapplication.getapplication().getdatabasepath("dandy")+".db"); file file = new file(environment.getexternalstoragedirectory(), "seeker.db"); filechannel inchannel = null,outchannel = null; try { file.createnewfile(); inchannel = new fileinputstream(dbfile).getchannel(); outchannel = new fileoutputstream(file).getchannel(); inchannel.transferto(0, inchannel.size(), outchannel); } catch (exception e) { logutils.e(tag, "copy database to sd error."); e.printstacktrace(); }finally{ try { if (inchannel != null) { inchannel.close(); inchannel = null; } if(outchannel != null){ outchannel.close(); outchannel = null; } } catch (ioexception e) { logutils.e(tag, "file close error."); e.printstacktrace(); } } }
以上这篇android 拷贝sqlite数据库到本地sd卡的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。
如对本文有疑问, 点击进行留言回复!!
android开发实例(activity生命周期和启动模式、IPC机制)
realme真我V5 5G发布会在哪看 8月3号realme真我V5直播地址入口
Android Studio中gradle文件下载慢解决办法
Android 应用进程 ServiceManager 的实现
Shimmer-Android使用FrameLayout给视图添加微光效果
网友评论