Java PrintWriter Write saveSet(Set set, File setFile, String encoding)

Here you can find the source of saveSet(Set set, File setFile, String encoding)

Description

Save set as string to a file.

License

Open Source License

Parameter

Parameter Description
set Set to save.
setFile Output file name.
encoding Character encoding for the file.

Exception

Parameter Description
IOExceptionIf output file has error.

Declaration


public static void saveSet(Set<?> set, File setFile, String encoding)
        throws IOException, FileNotFoundException 

Method Source Code


//package com.java2s;
/*   Please see the license information at the end of this file. */

import java.io.*;

import java.util.*;

public class Main {
    /**   Save set as string to a file.
     */* ww w  .j ava 2s  .com*/
     *   @param   set            Set to save.
     *   @param   setFile         Output file name.
     *   @param   encoding      Character encoding for the file.
     *
     *   @throws IOException      If output file has error.
     */

    public static void saveSet(Set<?> set, File setFile, String encoding)
            throws IOException, FileNotFoundException {
        if (set != null) {
            PrintWriter printWriter = new PrintWriter(setFile, "utf-8");

            Iterator<?> iterator = set.iterator();

            while (iterator.hasNext()) {
                String value = iterator.next().toString();

                printWriter.println(value);
            }

            printWriter.flush();
            printWriter.close();
        }
    }

    /**   Save set as string to a file name.
     *
     *   @param   set            Set to save.
     *   @param   setFileName      Output file name.
     *   @param   encoding      Character encoding for the file.
     *
     *   @throws IOException      If output file has error.
     */

    public static void saveSet(Set<?> set, String setFileName, String encoding)
            throws IOException, FileNotFoundException {
        saveSet(set, new File(setFileName), encoding);
    }
}

Related

  1. saveList(List list, OutputStream outs)
  2. saveMatrixAsADM(AtomicReferenceArray matrix, String path)
  3. saveMineField(File fileName, String mineField)
  4. saveProbabilityData(String file, double[] probabilities, double start, double dt)
  5. saveProcessedDataFile(double[][] data, String file)
  6. saveSortedMap(Map map, File mapFile, String separator, String qualifier, String encoding)
  7. saveString(String theFilePath, String theString)
  8. saveStringAsFile(String string, String path)
  9. saveStringBufferTofile(String fileName, StringBuffer sb)