how to write to a txt file in java

https:‮/‬/www.lautturi.com
how to write to a txt file in java
/**
 * @author lautturi.com
 * Java example: write a txt file in java
 */

import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.*;

public class Lautturi {

	public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException {

		// If the file does not exist, create one
		// Overwrite if file exists
		PrintWriter writer = new PrintWriter("test.txt", "UTF-8");
		writer.println("The first line");
		writer.println("The second line");
		writer.close();

	}
}
Created Time:2017-09-16 20:25:18  Author:lautturi