Here you can find the source of saveSet(Set> set, File setFile, String encoding)
Parameter | Description |
---|---|
set | Set to save. |
setFile | Output file name. |
encoding | Character encoding for the file. |
Parameter | Description |
---|---|
IOException | If output file has error. |
public static void saveSet(Set<?> set, File setFile, String encoding) throws IOException, FileNotFoundException
//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); } }