Android Text File Write writeSet2File(Set set, String filePath)

Here you can find the source of writeSet2File(Set set, String filePath)

Description

write Set File

License

Open Source License

Declaration

public static void writeSet2File(Set<String> set, String filePath)
        throws IOException 

Method Source Code

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();
    }
}

Related

  1. writeFileAtomically(File file, String content, String encoding)
  2. writeFileWithBom(File file, String content, String encoding)
  3. writeLargerTextFile(File file, List aLines)
  4. writeLineTextFile(File file, String data)
  5. writeLineTextFile(File file, String[] dataArray)
  6. writeString(String string, File file, boolean append)
  7. writeStringToFile(String content, String fileName)
  8. writeStringToFile(String content, String fileName, boolean append)
  9. writeStringToFile(String string, File file)