Java Text File Write nio writeFileTxt(String fileName, String[] totalFile)

Here you can find the source of writeFileTxt(String fileName, String[] totalFile)

Description

Method to get the file name (or path relative to the directory) and file to write to in the form of an array of strings where each string represents a line.

License

Open Source License

Parameter

Parameter Description
fileName name of the file (or path relative to directory)
totalFile array of strings where each string represents a line in the file

Declaration

public static void writeFileTxt(String fileName, String[] totalFile) throws IOException 

Method Source Code

//package com.java2s;
/**/*www  .  j ava2s .c  om*/
 * Copyright (C) 2016 Netflix, Inc.
 *
 *     This file is part of IMF Conversion Utility.
 *
 *     IMF Conversion Utility 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.
 *
 *     IMF Conversion Utility 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.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with IMF Conversion Utility.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.IOException;

import java.io.PrintWriter;
import java.io.Writer;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;

public class Main {
    /**
     * Method to get the file name (or path relative to the directory) and file to write to
     * in the form of an array of strings where each string represents a line.
     *
     * @param fileName name of the file (or path relative to directory)
     * @param totalFile array of strings where each string represents a line in the file
     */
    public static void writeFileTxt(String fileName, String[] totalFile) throws IOException {
        try (final Writer writer = Files.newBufferedWriter(Paths.get(fileName), Charset.forName("UTF-8"));
                PrintWriter pw = new PrintWriter(writer)) {
            for (String file : totalFile) {
                pw.println(file);
            }
        }
    }
}

Related

  1. writeContent(File file, String content)
  2. writeData(String address, BigInteger toWrite)
  3. writeDataFromList(String address, ArrayList toWrite)
  4. writeFileContent(File file, String content)
  5. writeFileContents(File file, String content)
  6. writeHeader(DataOutput data, String header)
  7. writeIfSet(final OutputStream outputStream, final String field, final String value)
  8. writeLine(final CharBuffer line, final CharBuffer output)
  9. writeLines(Collection lines, File file)