/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		ArrayList<String> data = new ArrayList<>(Arrays.asList("Перваая строка", "Вторая строка", "третья строка"));
        write("file.txt", data);
	}
	
	
	public static void write(String fileName, ArrayList<String> data) throws IOException {
        File file = new File(fileName);

        try {
            if(!file.exists()){
                file.createNewFile();
            }

            FileWriter writer = new FileWriter(file.getAbsoluteFile(), true);
            BufferedWriter bufferWriter = new BufferedWriter(writer);

            try {
                for (String string : data) {
                    bufferWriter.write(string);
                    bufferWriter.newLine();
                }
            } finally {
                bufferWriter.close();
            }
        } catch(IOException e) {
            throw new RuntimeException(e);
        }
    }
}