Here you can find the source of writeSet2File(Set
public static void writeSet2File(Set<String> set, String filePath) throws IOException
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.HashSet; import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class Main{ static Log log = LogFactory.getLog(FileUtil.class); //ww w .java 2 s .co m public static void writeSet2File(Set<String> set, String filePath) throws IOException { if (set == null || filePath == null || set.isEmpty()) { return; } File file = new File(filePath); if (!file.exists()) { if (log.isInfoEnabled()) { log.info("create file:" + file.getPath()); } file.createNewFile(); } BufferedWriter bw = new BufferedWriter(new FileWriter(file, true)); for (String str : set) { bw.write(str); bw.newLine(); } bw.close(); } }