开发者

Convert list in to byte[] for storing in SQLite in Android

开发者 https://www.devze.com 2023-01-16 04:41 出处:网络
I have this array declaration: List<GeoPoint> race = new ArrayList<Ge开发者_StackOverflow社区oPoint>();

I have this array declaration:

List<GeoPoint> race = new ArrayList<Ge开发者_StackOverflow社区oPoint>();

I want to store this array in to SQLite database.

Can some one give me code for converting this array in to byte[] or give me code for another solution ?

Thanks


If your GeoPoint is Serializable you can use a ByteArrayOutputStream plus an ObjectOutputStream.

ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(list);
byte[] result = baos.toByteArray();
oos.close();

Resources :

  • ObjectOutputStream
  • ByteArrayOutputStream
0

精彩评论

暂无评论...
验证码 换一张
取 消