android 拷貝sqlite數(shù)據(jù)庫到本地sd卡的方法
更新時間:2017年03月12日 11:37:13 投稿:jingxian
下面小編就為大家?guī)硪黄猘ndroid 拷貝sqlite數(shù)據(jù)庫到本地sd卡的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
sqlite小型數(shù)據(jù)庫,在開發(fā)的時候用于保存數(shù)據(jù),在這不做關于它的介紹,本文只是寫出了怎么拷貝應用的數(shù)據(jù)到本地sd卡中。如:一個數(shù)據(jù)庫名為dandy.db的,拷貝到本地中叫seeker.db
代碼如下:
/**
* 拷貝數(shù)據(jù)庫到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數(shù)據(jù)庫到本地sd卡的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
android中SwipeRefresh實現(xiàn)各種上拉,下拉刷新示例
這篇文章主要介紹了android中SwipeRefresh實現(xiàn)各種上拉,下拉刷新示例,非常具有實用價值,需要的朋友可以參考下。2017-03-03
Android 開源項目側邊欄菜單(SlidingMenu)使用詳解
SlidingMenu的是一種比較新的設置界面或配置界面效果,在主界面左滑或者右滑出現(xiàn)設置界面,能方便的進行各種操作.目前有大量的應用都在使用這一效果。如Evernote、Google+、Foursquare等,國內(nèi)的豌豆夾,人人,360手機助手等都使用SlidingMenu的界面方案。2016-05-05
Android垂直切換的圓角Banner與垂直指示器相關介紹與應用詳解
這篇文章主要介紹了Android垂直切換的圓角Banner與垂直指示器相關介紹與應用,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習吧2022-10-10
rxjava+retrofit實現(xiàn)多圖上傳實例代碼
本篇文章主要介紹了rxjava+retrofit實現(xiàn)多圖上傳實例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-06-06

