Here you can find the source of write(final Map
public static void write(final Map<String, String> dataBase, final File currentFile) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.Map; public class Main { private static final int POS_STEP = 5; private static final int BUF_SIZE = 4096; public static void write(final Map<String, String> dataBase, final File currentFile) throws IOException { OutputStream currentStream = new FileOutputStream(currentFile); BufferedOutputStream bufferStream = new BufferedOutputStream(currentStream, BUF_SIZE); DataOutputStream dataStream = new DataOutputStream(bufferStream); long biasing = 0; for (String key : dataBase.keySet()) { biasing += key.getBytes(StandardCharsets.UTF_8).length + POS_STEP; }/*ww w . ja v a 2s .c o m*/ List<String> values = new ArrayList<String>(dataBase.keySet().size()); for (String key : dataBase.keySet()) { String value = dataBase.get(key); values.add(value); dataStream.write(key.getBytes(StandardCharsets.UTF_8)); dataStream.writeByte(0); dataStream.writeInt((int) biasing); biasing += value.getBytes(StandardCharsets.UTF_8).length; } for (String value : values) { dataStream.write(value.getBytes()); } closeStream(dataStream); } private static void closeStream(final Closeable stream) throws IOException { stream.close(); } }