// Using the push back reader
import java.io.*;

class ReadCharacters
{
  public static void main(String[] args)
  {
    try
    {
      String dirName = "c:\\JunkData\\";         // Directory for the output file
      String fileName = "Proverbs.txt";          // Name of the output file 

      File input = new File(dirName, fileName);  // The file object

      PushbackReader in = new PushbackReader(
                                           new BufferedReader(
                                           new FileReader(input)));

      int c;                                     // Character store
      while(true)
      {
        String number ="";                       // String length as characters

        // Get the characters for the length
        while(Character.isDigit((char)(c = in.read())))
          number += (char)c;

        if(c==-1)                                // Check for end of file
          break;                                 // End the loop
        else                                     // It is not end of file so
          in.unread(c);                          // push back the last character

        char[] proverb = new char[Integer.parseInt(number)];
        in.read(proverb);                        // Read a proverb
        System.out.println(proverb);
      }
    }
    catch(FileNotFoundException e)               // Stream creation exception
    {
      System.err.println(e);
      return;
    }
    catch(IOException e)                         // File read exception
    {
      System.err.println("Error reading input file" + e );
      return;
    }
  }
}
