Java tutorial
import java.io.File; import java.io.FileNotFoundException; import java.util.Formatter; public class Main { public static void main(String[] args) { File file = new File("xyz.txt"); Formatter fm = null; try { // Create a Formatter that will write the output the file fm = new Formatter(file); // Formatting strings fm.format("%1$s, %2$s, and %3$s %n", "A", "B", "C"); fm.format("%3$s, %2$s, and %1$s %n", "A", "B", "C"); // Format more text here... } catch (FileNotFoundException e) { e.printStackTrace(); } finally { if (fm != null) { fm.close(); } } } }