Tag:android database
private void Copydbtosdcrad () {String database_name = "Database file name"; String OldPath = "data/data/com.packagename/databases/" + database_name; String NewPath = environment.getexternalstoragedirectory () + File.separator + database_name;copyfile (OldPath, NewPath) ;} /** * Copy a single file * * @param oldpath * String Original file path * @param newpath * string after copy path * @return Boolean */ public static void CopyFile (String oldpath, String newpath) {Try{int bytesum = 0;int byteread = 0; File Oldfile = new file (OldPath); File NewFile = new file (NewPath), if (!newfile.exists ()) {newfile.createnewfile ();} if (oldfile.exists ()) {//file exists InputStream instream = new FileInputStream (oldpath);//Read in original file FileOutputStream fs = new OutputStream (NewPath); byte[] buffer = new Byte[1444];while ((Byteread = instream.read (buffer))! =-1) {bytesum + = Byteread ; Number of bytes file size fs.write (buffer, 0, byteread);} Instream.close ();}} catch (Exception e) {System.out.println ("error copying Single file operation"); E.printstacktrace ();}}
Export a database from an Android program to an SD card