Java Text File Save writeFile(List fileLines, String pathname)

Here you can find the source of writeFile(List fileLines, String pathname)

Description

Writes a List of Strings, each String representing a line in the file, to the file at the specified pathname.

License

Open Source License

Parameter

Parameter Description
fileLines are the lines of file stored as a List of Strings, one String per line of the file
pathname is the path of the file to be created/modified

Declaration

public static void writeFile(List<String> fileLines, String pathname) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedWriter;

import java.io.FileWriter;
import java.io.IOException;

import java.util.Iterator;
import java.util.List;

public class Main {
    /**//from   ww  w  . j av  a 2s .  co  m
     * Writes a List of Strings, each String representing a line in the file,
     * to the file at the specified pathname. Each line in the output file will
     * be newline-terminated.
     *
     * @param fileLines are the lines of file stored as a List of Strings, one
     *                  String per line of the file
     * @param pathname  is the path of the file to be created/modified
     */
    public static void writeFile(List<String> fileLines, String pathname) {
        try {
            BufferedWriter writer = new BufferedWriter(new FileWriter(pathname));
            Iterator<String> lineIter = fileLines.iterator();
            if (lineIter.hasNext()) {
                writer.write(lineIter.next());
            }
            while (lineIter.hasNext()) {
                writer.newLine();
                writer.write(lineIter.next());
            }
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. writeFile(final String nameFile, final List listMsg)
  2. writeFile(final String outputDir, final String response, final String fileName)
  3. writeFile(IFile annotationFile, StringBuffer head, String annotatedSignature, String nextLines, BufferedReader tailReader, IProgressMonitor monitor)
  4. writeFile(IFile file, final InputStream contents, final String charset, IProgressMonitor monitor)
  5. writeFile(List data, File f)
  6. writeFile(List lines, String filePath)
  7. writeFile(List strList, String fileFullPath)
  8. writeFile(List txtList, String MyFilePath)
  9. writeFile(String file, String content)