Here you can find the source of writeDataFromList(String address, ArrayList
public static void writeDataFromList(String address, ArrayList<BigInteger> toWrite) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.math.BigInteger; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; public class Main { public static void writeDataFromList(String address, ArrayList<BigInteger> toWrite) throws IOException { ArrayList<Byte[]> data = new ArrayList<>(); for (BigInteger bi : toWrite) { byte[] byteArr = bi.toByteArray(); Byte[] ByteArr = new Byte[byteArr.length]; for (int i = 0; i < byteArr.length; i++) ByteArr[i] = byteArr[i]; data.add(ByteArr);// ww w . j av a 2 s. c o m } int lastElLen = 0; for (lastElLen = 0; lastElLen < data.get(data.size() - 1).length; lastElLen++) { if (data.get(data.size() - 1)[lastElLen] == 0) { break; } } byte[] combinedArr = new byte[((data.size() - 1) * data.get(0).length) + lastElLen]; int j = 0; for (Byte[] arr : data) { for (Byte arrEl : arr) { combinedArr[j] = arrEl; j++; if (j == combinedArr.length) break; } } BigInteger combined = new BigInteger(combinedArr); writeData(address, combined); } public static void writeData(String address, BigInteger toWrite) throws IOException { Path path = Paths.get(address); byte[] data = toWrite.toByteArray(); Files.write(path, data); } }