Here you can find the source of writeFile(List
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 |
public static void writeFile(List<String> fileLines, String pathname)
//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(); } } }