// 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.*;

public class TextFile {
   public static void main(String[] args) throws Exception {
      Data[] x1 = new Data[4];
      for(int i = 0; i < x1.length; i++) {
         x1[i] = null;
      }
      x1[0] = new Data(1, "a");
      x1[1] = new Data(2, "bb");
      x1[2] = new Data(3, "ccc");
      PrintStream ps = new PrintStream(new FileOutputStream("C:\\test.txt"));
      for(int i = 0; i < x1.length; i++) {
         if(x1[i] != null) {
            ps.println(x1[i].getA() + " " + x1[i].getB());
         }
      }
      ps.close();
      Data[] x2 = new Data[4];
      for(int i = 0; i < x2.length; i++) {
         x2[i] = null;
      }
      BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("C:\\test.txt")));
      String line;
      int ix = 0;
      while((line = br.readLine()) != null) {
         x2[ix] = new Data(Integer.parseInt(line.substring(0,1)), line.substring(1).trim());
         ix++;
      }
      br.close();
      for(int i = 0; i < x2.length; i++) {
         if(x2[i] != null) {
            System.out.println(x2[i].getA() + " " + x2[i].getB());
         }
      }
   }
}

class Data {
   private int a;
   private String b;
   public Data() {
      a = 0;
      b = "";
   }
   public Data(int a, String b) {
      this.a = a;
      this.b = b;
   }
   public int getA() {
      return a;
   }
   public String getB() {
      return b;
   }
   public void setA(int a) {
      this.a = a;
   }
   public void setB(String b) {
      this.b = b;
   }
}
