Android Code Snippet Copy from Dir.Internal to SD Card using ExternalStorage

I was looking for help on copying data from Dir.Internal to an SD Card using the ExternalStorage class and noticed a few other people couldn't quite get to grips with it either. So for them here's an example, which works for me. Took me a while to get something to work, but got there eventually. Works for me anyway.

B4X:
Try
   Storage.SelectDir(False)
   Wait For Storage_ExternalFolderAvailable
   Dim lFileName As String="test.db"
   Dim InputStream1 As InputStream
   InputStream1 = File.OpenInput(File.Dirinternal, lFileName)
   Dim lFile As ExternalFile
   lFile=Storage.CreateNewFile(Storage.root,lFileName)
   Dim outputstream1 As OutputStream
   outputstream1= Storage.OpenOutputstream(lFile)
   File.copy2(InputStream1,outputstream1)
   InputStream1.Close
   outputstream1.close
   Msgbox2("Database copied. File Name: "&lFileName,"Info","OK","","",Null)
Catch
   Log(LastException)
End Try

Remember you'll need the ExternalStorage class. You can get it by searching the forum.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…