Java Write String to File writeFile(File file, String... lines)

Here you can find the source of writeFile(File file, String... lines)

Description

write File

License

Apache License

Declaration

public static void writeFile(File file, String... lines) throws IOException 

Method Source Code

//package com.java2s;
/**// w w  w. j  a  v  a2  s  . c  o  m
 * Copyright (C) 2014 Dasasian (damith@dasasian.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.*;

public class Main {
    public static void writeFile(File file, String... lines) throws IOException {
        BufferedWriter writer = new BufferedWriter(new FileWriter(file));
        for (String line : lines) {
            writer.append(line);
            writer.newLine();
        }
        writer.close();
    }
}

Related

  1. writeFile(File file, String data)
  2. writeFile(File file, String data, boolean append)
  3. writeFile(File file, String dataString)
  4. writeFile(File file, String text)
  5. writeFile(File file, String text)
  6. writeFile(File file, String... lines)
  7. writeFile(File file, StringBuffer buffer)
  8. writeFile(File filename, ArrayList lines)
  9. writeFile(final File file, final String content)