Getting a Object from an included asset file:


private static Object getObjectFromAssetsFile(Context context) {

  try {
    InputStream is = null;
    ObjectInputStream ois = null;

    AssetManager assets = context.getAssets();
    is = assets.open(file_name);
    ois = new ObjectInputStream(is);

    Object o = ois.readObject();
                
    // Check object type and cast as required right here 
    
    return o;

  } catch (FileNotFoundException e) {
    e.printStackTrace();
  } catch (IOException e) {
    e.printStackTrace();
  } catch (ClassNotFoundException e) {
    e.printStackTrace();
  } catch (Exception e) {// Catch exception if any
    e.printStackTrace();
  }
  return null;
}

Copying an SQLite Database from the assets folder to the app's data folder:


public static void copyDB(Context context, String assetFileName, String outFileName)
      throws IOException {
  InputStream inputStream = context.getAssets().open(assetFileName);
  OutputStream outputStream = new FileOutputStream(outFileName);

  // ---copy 1K bytes at a time---
  byte[] buffer = new byte[1024];
  int length;
  while ((length = inputStream.read(buffer)) > 0) {
    outputStream.write(buffer, 0, length);
  }
  inputStream.close();

  outputStream.flush();
  outputStream.close();
}