SoFunction
Updated on 2025-03-11

Android method to copy SQLite database to local SD card

The sqlite small database is used to save data during development. I will not introduce it here. This article just writes about how to copy the application data into the local SD card. For example: a database named, copying it to the local area is called

The code is as follows:

	/**
	  * Copy the database to the SD card
	  *
	  * @deprecated <uses-permission android:name=".WRITE_EXTERNAL_STORAGE"/>
	  */
	public static void copyDataBaseToSD(){
		 if (!Environment.MEDIA_MOUNTED.equals(())) {
       return ;
     }
		 File dbFile = new File(().getDatabasePath("dandy")+".db");
		 File file = new File((), "");
		 
		 FileChannel inChannel = null,outChannel = null;
		 
		 try {
			();
			inChannel = new FileInputStream(dbFile).getChannel();
			outChannel = new FileOutputStream(file).getChannel();
			(0, (), outChannel);
		} catch (Exception e) {
			(TAG, "copy dataBase to SD error.");
			();
		}finally{
			try {
				if (inChannel != null) {
					();
					inChannel = null;
				}
				if(outChannel != null){
					();
					outChannel = null;
				}
			} catch (IOException e) {
				(TAG, "file close error.");
				();
			}
		}
	}

The above method of copying the sqlite database to the local SD card on Android is all the content I share with you. I hope you can give you a reference and I hope you can support me more.