Java FileWriter Write saveFile(List contents, String fileName)

Here you can find the source of saveFile(List contents, String fileName)

Description

save File

License

Apache License

Declaration

public static void saveFile(List<String> contents, String fileName) throws IOException 

Method Source Code


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

import java.io.*;

import java.util.List;

public class Main {
    public static void saveFile(List<String> contents, String fileName) throws IOException {
        File file = new File(fileName);
        saveFile(contents, file);/* w w  w.  j a v  a2  s.  co m*/
    }

    public static void saveFile(List<String> contents, File file) throws IOException {
        FileWriter writer = null;
        if (file.exists()) {
            throw new IOException("already exists: " + file.getAbsolutePath());
        }
        try {
            writer = new FileWriter(file);
            for (String content : contents) {
                writer.write(content);
                writer.write("\r\n");
            }
        } finally {
            if (writer != null) {
                writer.close();
            }
        }
    }
}

Related

  1. saveFile(File directory, String fileName, String content)
  2. saveFile(File file, String contents)
  3. saveFile(File file, String data)
  4. saveFile(File file, String fileContent)
  5. saveFile(File file, String text, boolean append)
  6. saveFile(String filePath, String content)
  7. saveFile(String filePath, String data)
  8. saveFile(String path, Map> setup)
  9. saveFile(String path, String content)