How can I append data in file without making it clean after FileInputStream(...)
?
That's how I append from my HashMap <String, String> storage
:
DataOutputStream stream = new DataOutputStream(new FileOutputStream("myfile.dat"));
for (Map.Entry<String, String> entry : storage.entrySet()) {
byte[] bytesKey = entry.getKey().getBytes("UTF-8"); //I need to write using UTF8
stream.writeInt(bytesKey.length);
stream.write(bytesKey);
byte[] bytesVal = entry.getValue().getBytes("UTF-8");
stream.write(bytesVal);
}
stream.close();
So, the problem is when I turn it on again it clears all the previous data in my file. How to avoid that?