Java FileWriter Write saveGraph(List> graph, String sFileName)

Here you can find the source of saveGraph(List> graph, String sFileName)

Description

Saves a graph into a csv file in the format of tuples (vertex,edge) for every edge in the graph.

License

GNU General Public License

Declaration

public static void saveGraph(List<List<Integer>> graph, String sFileName) throws IOException 

Method Source Code

//package com.java2s;
/**//  w w w  .  java 2s . c om
 *                    BioJava development code
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  If you do not have a copy,
 * see:
 *
 *      http://www.gnu.org/copyleft/lesser.html
 *
 * Copyright for this code is held jointly by the individual
 * authors.  These should be listed in @author doc comments.
 *
 * For more information on the BioJava project and its aims,
 * or to join the biojava-l mailing list, visit the home page
 * at:
 *
 *      http://www.biojava.org/
 *
 * Created on Oct 5, 2011
 * Created by Andreas Prlic
 *
 * @since 3.0.2
 */

import java.io.FileWriter;
import java.io.IOException;

import java.util.List;

public class Main {
    /**
     * Saves a graph into a csv file in the format of tuples (vertex,edge) for every edge in the graph.
     * The graph has to be in the form of an adjacency list.
     */
    public static void saveGraph(List<List<Integer>> graph, String sFileName) throws IOException {

        FileWriter writer = new FileWriter(sFileName);
        writer.append("Vertex,Edge\n");
        for (Integer i = 0; i < graph.size(); i++) {
            for (int j = 0; j < graph.get(i).size(); j++) {

                writer.append(i.toString());
                writer.append(',');
                writer.append(graph.get(i).get(j).toString());
                writer.append('\n');
            }
        }

        writer.flush();
        writer.close();
    }
}

Related

  1. saveFileContents(File file, String contents)
  2. saveFileFromString(File file, String encoding, String content)
  3. saveFiles(final List contents, final File outputDirectory, final String outputName, final String fileExtension)
  4. saveFlows(Map differences, String file)
  5. saveFormedClustersToFile(Vector names, Collection> clusters, String filename)
  6. saveIndex(File root_, Hashtable index)
  7. saveInputStreamInFile(InputStream stream, FileWriter f)
  8. saveIntegerNodes2File(Integer[] nodes, String fileName)
  9. saveIntNodes2File(int[] nodes, String fileName)