Java FileWriter Write saveData(Map> data, File file)

Here you can find the source of saveData(Map> data, File file)

Description

Saves the dataset.

License

Open Source License

Parameter

Parameter Description
data the dataset.
file the file handler.

Exception

Parameter Description
IOException if error occurs.

Declaration

public static void saveData(Map<String, List<double[]>> data, File file)
        throws IOException 

Method Source Code

//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();
    }
}

Related

  1. saveBufferInFile(String buffer, File filename)
  2. saveCCS(Map contributionScore, String diseaseState, String file)
  3. saveColumn(int[] density, String filename)
  4. saveConfig(File conf, Map data)
  5. saveContent(String context, String filename)
  6. saveData(Map> data, String file)
  7. saveData(String fileName, double totalTime, int[] resultSubset)
  8. saveDictionary(String fileName, Map values)
  9. saveDotGraph(final String dotGraph, final File outputDirectory)