I'm basically looking for a way to save and reload a few large arrays (about 5 million short
) in a fastish way on Android. My app needs to save them in a way where I could get back to them much later, so I can't just hold them in memory...
So far, I've tried converting them to a byte[]
array and they seem to save successfully, but I can't get the data back, this is how my saving code works (it's actually to separate functions, simplified here):
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOuputStream oos = new ObjectOutputStream(baos);
oos.writeObject(data);
oos.close();
baos.close();
FileOutputStream fos = new FileOutputStream(filename); // valid absolute path
fos.write(baos.toByteArray());
fos.close();
And the loading part is where I get stuck, how do I get a short[]
from a byte[]
?
I also read that a database might work too, but is it quick enough?
I've looked all around Stackoverflow and Google and can't seem to find somebody with a similar problem, or at least a solution to it, but as a beginner I might have missed something obvious...