Here you can find the source of writeFile(File filename, ArrayList lines)
Parameter | Description |
---|---|
filename | full path |
public static void writeFile(File filename, ArrayList lines)
//package com.java2s; /** /*from ww w . j av a2 s . c o m*/ * IOUtils.java * * Copyright (c) 2006, JULIE Lab. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * * Author: tomanek * * Current version: 2.3 * Since version: 2.2 * * Creation date: Nov 1, 2006 * * Some more utils for JNET. * **/ import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; public class Main { /** * writes ArrayList into file. Here, we assume that each element of the * ArrayList is a String, which we write as new line into the file. * * @param filename * full path */ public static void writeFile(File filename, ArrayList lines) { try { FileWriter fw = new FileWriter(filename); for (int i = 0; i < lines.size(); i++) fw.write((String) lines.get(i) + "\n"); fw.close(); } catch (IOException e) { System.err.println("error writing file"); e.printStackTrace(); } } public static void writeFile(File filename, String myString) { try { FileWriter fw = new FileWriter(filename); fw.write(myString + "\n"); fw.close(); } catch (IOException e) { System.err.println("error writing file"); e.printStackTrace(); } } }