Java Text File Save writeFile(File outputFile, ArrayList sortedLines, String lineSeparator)

Here you can find the source of writeFile(File outputFile, ArrayList sortedLines, String lineSeparator)

Description

write File

License

Open Source License

Declaration

static void writeFile(File outputFile, ArrayList<String> sortedLines, String lineSeparator) throws IOException 

Method Source Code

//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
                }
            }
        }
    }
}

Related

  1. setText(File file, String text)
  2. writeFile(ArrayList lines, String dest_path)
  3. writeFile(Collection emailTree, String destFile)
  4. writeFile(File destinationFile, String contents, String encoding)
  5. writeFile(File outputDirectory, String fileName, String source)
  6. writeFile(File outputFile, String text)
  7. writeFile(File outputFolder, String fileName, String content)
  8. writeFile(File path, File file, String content)
  9. writeFile(File path, String fileName, String fileContent)