Java File Write nio writeFile(OutputStream file, List data)

Here you can find the source of writeFile(OutputStream file, List data)

Description

write File

License

Apache License

Declaration

public static void writeFile(OutputStream file, List<String> data) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.BufferedWriter;

import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;

import java.util.List;

public class Main {
    private static final String S_NEWLINE = System.getProperty("line.separator");

    public static void writeFile(OutputStream file, List<String> data) {
        BufferedWriter bufferedWriter = null;
        try {//  w  ww  .j a v  a  2 s  . com
            bufferedWriter = new BufferedWriter(new OutputStreamWriter(file, Charset.defaultCharset()));
            for (String line : data) {
                bufferedWriter.write(line);
                bufferedWriter.write(S_NEWLINE);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            try {
                if (bufferedWriter != null) {
                    bufferedWriter.flush();
                    bufferedWriter.close();
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
}

Related

  1. writeFile(File file, String content)
  2. writeFile(File file, String content)
  3. writeFile(File file, String text)
  4. writeFile(FileObject fileObject, String content)
  5. writeFile(List content, String targetFile)
  6. writeFile(String filename, byte file[])
  7. writeFile(String fileName, String content)
  8. writeFile(String fileName, String content)
  9. writeFile(String folder, String aFileName, String aItem)