Here you can find the source of saveData(Map
Parameter | Description |
---|---|
data | the dataset. |
file | the file handler. |
Parameter | Description |
---|---|
IOException | if error occurs. |
public static void saveData(Map<String, List<double[]>> data, File file) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Map.Entry; public class Main { private static final String CR = "\n"; /**//from ww w . j a v a2 s . c o m * Saves the dataset. * * @param data the dataset. * @param file the file handler. * @throws IOException if error occurs. */ public static void saveData(Map<String, List<double[]>> data, File file) throws IOException { BufferedWriter bw = new BufferedWriter(new FileWriter(file)); for (Entry<String, List<double[]>> classEntry : data.entrySet()) { String classLabel = classEntry.getKey(); for (double[] arr : classEntry.getValue()) { String arrStr = Arrays.toString(arr).replaceAll( "[\\]\\[\\s]+", ""); bw.write(classLabel + "," + arrStr + CR); } } bw.close(); } }