欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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ù),在這不做關(guān)于它的介紹,本文只是寫出了怎么拷貝應(yīng)用的數(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)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論