simple text formatter as in textbook code example

Example: simple text formatter as in textbook

import java.io.*; import java.util.*; /** * Fmt - format text (like Berkeley Unix fmt). */ public class Fmt { /** The maximum column width */ public static final int COLWIDTH=72; /** The file that we read and format */ BufferedReader in; /** If files present, format each, else format the standard input. */ public static void main(String[] av) throws IOException { if (av.length == 0) new Fmt(System.in).format( ); else for (int i=0; i<av.length; i++) new Fmt(av[i]).format( ); } /** Construct a Formatter given a filename */ public Fmt(String fname) throws IOException { in = new BufferedReader(new FileReader(fname)); ...

Tags:

Java Example