// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.*;
import java.util.*;

public class PrettyPrintJava15 {
    public static void format(String infnm, String outfnm) throws IOException {
        Scanner scn = new Scanner(new FileInputStream(infnm));
        PrintWriter pw = new PrintWriter(new FileOutputStream(outfnm));
        String temp = scn.next();
        while (scn.hasNext()) {
            String word = scn.next();
            if(temp.length() + 1 + word.length() > 10) {
                pw.println(temp);
                temp = word;
            } else {
                temp = temp + " " + word;
            }
        }
        if(temp.length() > 0) {
            pw.println(temp);
        }
        pw.close();
    }
    public static void main(String[] args) throws Exception {
        PrettyPrintJava15.format("C:\\test.txt", "C:\\testout.txt");
    }
}
