Here you can find the source of writeFile(List
Parameter | Description |
---|---|
lines | the list of lines to write. |
outFile | the path to the file to write to. |
Parameter | Description |
---|---|
IOException | an exception |
public static void writeFile(List<String> lines, String filePath) throws IOException
//package com.java2s; /*// w w w . jav a 2 s.c o m * Stage - Spatial Toolbox And Geoscript Environment * (C) HydroloGIS - www.hydrologis.com * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * (http://www.eclipse.org/legal/epl-v10.html). */ import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.List; public class Main { /** * Write text to a file in one line. * * @param text the text to write. * @param file the file to write to. * @throws IOException */ public static void writeFile(String text, File file) throws IOException { BufferedWriter bw = null; try { bw = new BufferedWriter(new FileWriter(file)); bw.write(text); } finally { if (bw != null) bw.close(); } } /** * Write a list of lines to a file. * * @param lines the list of lines to write. * @param outFile the path to the file to write to. * @throws IOException */ public static void writeFile(List<String> lines, String filePath) throws IOException { writeFile(lines, new File(filePath)); } /** * Write a list of lines to a file. * * @param lines the list of lines to write. * @param file the file to write to. * @throws IOException */ public static void writeFile(List<String> lines, File file) throws IOException { BufferedWriter bw = null; try { bw = new BufferedWriter(new FileWriter(file)); for (String line : lines) { bw.write(line); bw.write("\n"); //$NON-NLS-1$ } } finally { if (bw != null) bw.close(); } } }