Java FileWriter Write save(Map map, String path)

Here you can find the source of save(Map map, String path)

Description

save

License

Open Source License

Declaration

public static void save(Map<String, Integer> map, String path) 

Method Source Code

//package com.java2s;
/**/*  w  ww. ja va2 s . c  om*/
 * Copyright (c) 2011-2013 Armin T?pfer
 *
 * This file is part of QuasiRecomb.
 *
 * QuasiRecomb is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or any later version.
 *
 * QuasiRecomb is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * QuasiRecomb. If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.*;
import java.util.*;

public class Main {
    public static void save(Map<String, Integer> map, String path) {
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<String, Integer> read : map.entrySet()) {
            for (int i = 0; i < read.getValue(); i++) {
                sb.append(">").append(i).append("\n").append(read.getKey()).append("\n");
            }
        }
        saveFile(path, sb.toString());
    }

    public static void saveFile(String path, String sb) {
        try {
            // Create file
            FileWriter fstream = new FileWriter(path);
            try (BufferedWriter out = new BufferedWriter(fstream)) {
                out.write(sb);
            }
        } catch (Exception e) {//Catch exception if any
            System.err.println("Error save file: ");
            System.err.println(path);
            System.err.println(sb);
        }
    }
}

Related

  1. save(File file, String content)
  2. save(File file, String text)
  3. save(File pFile, String pString)
  4. save(final String content, final String file)
  5. save(List list, String REPO)
  6. save(String fileName, Object o)
  7. save(String fileName, String dataToSave)
  8. save(String modelo, String filename)
  9. save(String targetDir, String filename, String textToSave)