If so I'm wondering how I would append to the file and not overwrite.
That's easy - and you don't even need DataOutputStream
. Just FileOutputStream
is fine, using the constructor with an append
parameter:
FileOutputStream output = new FileOutputStream("filename", true);
try {
output.write(data);
} finally {
output.close();
}
Or using Java 7's try-with-resources:
try (FileOutputStream output = new FileOutputStream("filename", true)) {
output.write(data);
}
If you do need DataOutputStream
for some reason, you can just wrap a FileOutputStream
opened in the same way.