Java Text File Write nio writeToFile(String filename, String... lines)

Here you can find the source of writeToFile(String filename, String... lines)

Description

write To File

License

Open Source License

Declaration

public static boolean writeToFile(String filename, String... lines) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Main {
    public static boolean writeToFile(String filename, String... lines) {
        Path p = Paths.get(filename);
        try (BufferedWriter bw = new BufferedWriter(Files.newBufferedWriter(p))) {
            for (String l : lines) {
                bw.write(l);//ww  w.jav a  2  s.c  om
                bw.newLine();
            }
        } catch (IOException ex) {
            return false;
        }
        return true;
    }
}

Related

  1. writeToFile(File file, String str)
  2. writeToFile(final File file, final String data)
  3. writeToFile(String content, String fileName)
  4. writeToFile(String content, String fileName, boolean createFile)
  5. writeToFile(String filename, String fileContents)
  6. writeTokenText(OutputStream theOs, String theStr)
  7. writeToTextFile(String fileName, String content)