Here you can find the source of writeAllLines(File file, List
public static void writeAllLines(File file, List<String> list) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2013, 2014 ETAS GmbH.// w w w . j a v a 2s . c o m * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Dennis Eder (ETAS GmbH) - initial API and implementation and/or initial documentation *******************************************************************************/ import java.io.BufferedWriter; import java.io.File; import java.io.IOException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; public class Main { final static Charset ENCODING = StandardCharsets.UTF_8; public static void writeAllLines(File file, List<String> list) throws IOException { writeAllLines(file, list.toArray(new String[] {})); } public static void writeAllLines(File file, String[] lines) throws IOException { Path path = file.toPath(); try (BufferedWriter writer = Files.newBufferedWriter(path, ENCODING)) { for (String line : lines) { writer.write(line); writer.newLine(); } } } }