Convert list in to byte[] for storing in SQLite in Android
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
加载中,请稍侯......
精彩评论