Java FileWriter Write saveIntNodes2File(int[] nodes, String fileName)

Here you can find the source of saveIntNodes2File(int[] nodes, String fileName)

Description

save int nodes to the fileName

License

Open Source License

Declaration

public static void saveIntNodes2File(int[] nodes, String fileName) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.*;

public class Main {
    /**//from w  w  w . j a  va 2 s  .co  m
     * save int nodes to the fileName
     */
    public static void saveIntNodes2File(int[] nodes, String fileName) {
        FileWriter fw = null;
        try {
            fw = new FileWriter(fileName);
            String str = "";
            if (nodes != null) {
                for (int i = 0; i < nodes.length; i++) {
                    str = str + nodes[i];
                    str = str + "\n";
                }
            } else {
                str = "null";
            }
            fw.write(str);
            fw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    /**
     * save int nodes to the fileName
     */
    public static void saveIntNodes2File(long[] nodes, String fileName) {
        FileWriter fw = null;
        try {
            fw = new FileWriter(fileName);
            String str = "";
            if (nodes != null) {
                for (int i = 0; i < nodes.length; i++) {
                    str = str + nodes[i];
                    str = str + "\n";
                }
            } else {
                str = "null";
            }
            fw.write(str);
            fw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    /**
     * save int nodes to the fileName
     */
    public static void saveIntNodes2File(int[] nodes, String fileName, double score) throws IOException {
        FileWriter fw = null;
        fw = new FileWriter(fileName);
        String date = fileName.split("\\.")[0];
        String str = "";
        if (nodes != null) {
            for (int i = 0; i < nodes.length; i++) {
                str = str + nodes[i] + " " + String.valueOf(score) + " " + date + "\n";
                str = str + "\n";
            }
        } else {
            str = "null";
        }
        fw.write(str);
        fw.close();
    }
}

Related

  1. saveFormedClustersToFile(Vector names, Collection> clusters, String filename)
  2. saveGraph(List> graph, String sFileName)
  3. saveIndex(File root_, Hashtable index)
  4. saveInputStreamInFile(InputStream stream, FileWriter f)
  5. saveIntegerNodes2File(Integer[] nodes, String fileName)
  6. saveList(String listName, Set list)
  7. saveListStringToFile(String filePath, List listString)
  8. saveListToFile(ArrayList list, String filePath)
  9. saveMap(Map map, String filePath)