// 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 ReadAndSort {
   public static void main(String[] args) throws Exception {
      PrintStream ps = new PrintStream(new FileOutputStream("C:\\test.txt"));
      ps.println("a");
      ps.println("bb");
      ps.println("ccc");
      ps.println("a1");
      ps.println("a2");
      ps.println("a3");
      ps.println("ab");
      ps.println("abc");
      ps.println("x2");
      ps.println("x1");
      ps.close();
      BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("C:\\test.txt")));
      String[] words = new String[10];
      String line;
      int ix = 0;
      while ((line = br.readLine()) != null) {
         words[ix] = line;
         ix++;
      }
      br.close();
      Arrays.sort(words);
      System.out.println(words[(int)(10*Math.random())]);
   }
}
