Snippet that copies a db to resources/raw for distribution?

Put your problem here if it does not fit any of the other categories.

Snippet that copies a db to resources/raw for distribution?

Postby Omar » Mon Mar 17, 2008 8:58 pm

Hi,

My app contains a sqlite db that will be opened by the end user.
So far I have tried an approach I have found to place the text file in the resources/raw. From there I will read it and generate the db.
I am wondering though, is there an easier approach?
With this approach I am pursuing, so far I am running into the issue that the exception is kicking in, rather than the file being displayed. The file is in the resources.ap_ though.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  private void readFileFromLocal( Context context )
  2.  
  3.     {
  4.  
  5.     InputStream istream = null;
  6.  
  7.     try {
  8.  
  9.     istream = context.getResources().openRawResource(R.raw.out2);
  10.  
  11.     String s;
  12.  
  13.     int i;
  14.  
  15.     istream.read(b, 0,100);
  16.  
  17.     s = b +"";
  18.  
  19.     Log.i("msg",s);
  20.  
  21.  
  22.  
  23.  
  24.  
  25.     } catch (Exception FileNotFoundException){
  26.  
  27.     Log.v("File not found exception!", "hoy");
  28.  
  29.     }
  30.  
  31.     }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


Is there some snippet out there that copies the SQLite db to resources/raw and from there it can be simply copied to the filessytem? I have found some methods under java.io.File: "mkdir", "create" and "rename" file, but not "copy":

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. String path2 = "/data/data/com.google.ha1/omar/";
  2.  
  3.      File dir = new File(path2);
  4.  
  5.      dir.mkdir();
  6.  
  7.         File temp = File.createTempFile("mediaplayertmp",".txt", file);
  8.  
  9.                 temp.renameTo(filedest);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4



Many thanks for your help,
Omar F
Omar
Freshman
Freshman
 
Posts: 2
Joined: Mon Mar 17, 2008 8:40 pm
Location: Reston

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot] and 14 guests