If you plan to write into a local file you need to chain FileOutputStream
, BufferedOutputStream
and ObjectOutputStream
. With below setup BufferedOutputStream
should minimize direct writes to the file system using default buffer of 8192 bytes.
Map<String, List<String>> data = new HashMap<>();
data.put("myKey", List.of("A", "B", "C"));
File outFile = new File("out.bin");
try (FileOutputStream fos = new FileOutputStream(outFile);
BufferedOutputStream bos = new BufferedOutputStream(fos);
ObjectOutputStream oos = new ObjectOutputStream(bos)) {
oos.writeObject(data);
oos.flush();
}
Unless the output file is too big there is no need for further chunking.