Java FileOutputStream Write saveStringsList(String file, Collection c)

Here you can find the source of saveStringsList(String file, Collection c)

Description

save Strings List

License

Open Source License

Declaration

public static void saveStringsList(String file, Collection<String> c)
            throws FileNotFoundException, IOException 

Method Source Code

//package com.java2s;
/*// w  ww  .  j a  v  a  2  s . co m
 * Copyright (C) ${year} Omry Yadan <${email}>
 * All rights reserved.
 *
 * See https://github.com/omry/banana/blob/master/BSD-LICENSE for licensing information
 */

import java.io.*;

import java.util.*;

public class Main {
    public static void saveStringsList(String file, Collection<String> c)
            throws FileNotFoundException, IOException {
        saveStringsList(file, c, false);
    }

    public static void saveStringsList(String file, Collection<String> c, boolean append)
            throws FileNotFoundException, IOException {
        File p = new File(file).getParentFile();
        if (p != null)
            p.mkdirs();

        FileOutputStream fout = new FileOutputStream(file, append);
        try {
            for (String subjectID : c) {
                fout.write((subjectID + "\n").getBytes());
            }
        } finally {
            fout.close();
        }
    }
}

Related

  1. saveStream(InputStream stream, File targetFile)
  2. saveStreamToFile(InputStream in, File outFile)
  3. saveStreamToFile(InputStream is, File destFile)
  4. saveStringIntoFile(File file, String contents)
  5. saveStringIntoFile(String filePath, String contents)
  6. saveStringToFile(File file, String content, String charset)
  7. saveTemp(final byte[] data, final String suffix)
  8. saveTempFile(String xmlSource, String fileName)
  9. saveTextContentInFile(String content, File file)