0

This question is in a similar vein to my recent question (How would I store an ArrayList<String[]> in order to compare it to a new one later?), except I actually ended up coming up with a solution for that. The solution was to use MessageDigest to convert each part of each contact into a byte[] array, instead of trying to store the finalized ArrayList of String[] objects. It then does the same with the old contact list, and then compares the two calculated byte[] arrays for equality. The issue I'm dealing with now is that I wish to be able to store/retrieve specifically the "old contact book" byte[] array persistently across device reboots... but using SharedPreferences is off the table, since contact books could potentially be very large, and SharedPreferences is intended to be used for smaller key-value pairs (not to mention my peers have advised against it in this case).

I've tried using the FileOutputStream and FileInputStream classes, with a BufferedReader... but that seems to only work for Characters and Strings, not byte[] arrays. (reference documentation: https://developer.android.com/training/data-storage/app-specific#internal-access-files) In addition to the FileOutput/InputStream and BufferedReader classes I saw, there was something else about caching (https://developer.android.com/training/data-storage/use-cases#cache-non-media and https://developer.android.com/reference/android/content/Context#getCacheDir() , respectively) but I wasn't sure how to start with it based off of the documentation.

Is there a method that I can use to store and then retrieve (on reboot) a byte[] array, without using SharedPreferences?

mbob98
  • 61
  • 6
  • "I've tried using the FileOutputStream and FileInputStream classes, with a BufferedReader... but that seems to only work for Characters and Strings, not byte[] arrays" -- `FileInputStream` and `FileOutputStream` can work with binary data. See [the `write()` method on `FileOutputStream`](https://developer.android.com/reference/java/io/FileOutputStream?hl=en#write(byte[])) and [the various `read()` methods on `FileInputStream`](https://developer.android.com/reference/java/io/FileInputStream?hl=en#read(byte[])). – CommonsWare May 19 '22 at 21:11

0 Answers0