Here you can find the source of writeFile(File outputFile, ArrayList
static void writeFile(File outputFile, ArrayList<String> sortedLines, String lineSeparator) throws IOException
//package com.java2s; /**/*w ww . j a va2 s. c o m*/ * TaskUtils.java * * Copyright (C) 2010, Volker Boerchers * * Translator.java is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Translator.java is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.util.ArrayList; public class Main { static void writeFile(File outputFile, ArrayList<String> sortedLines, String lineSeparator) throws IOException { BufferedWriter out = null; try { out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), "US-ASCII")); for (String line : sortedLines) { out.write(line.replaceAll("\\\\[\n\r]+", "\\\\" + lineSeparator)); // change this to write(<sep>) to enforce Unix or Dos or Mac newlines out.write(lineSeparator); } } finally { if (out != null) { try { out.close(); } catch (IOException e) { // can't help it } } } } }