title: How to over ride a InputStream method read() to return a character?
body: <p>The question was: Develop a class <code>ConvertToLowerCase</code> that derives from <code>FileInputStream</code> and overrides the <code>read()</code> method that is derived from <code>FileInputStream</code> such that overriding <code>read()</code> method returns a lower case character.  Use this class to convert the file information in <code>in.txt</code> to lowercase text and write it to the file <code>out.txt</code>.</p>
  
  <p>The problem is that the program crashes in the middle and gives an error of unhandled heap, and it doesn't print the last word i.e. head in the <code>out.txt</code></p>
  
  <p>Here's the in.txt: </p>
  
  <pre><code>How High he holds His Haughty head
  </code></pre>
  
  <p>Here's the out.txt: </p>
  
  <pre><code>how high he holds his haughty 
  </code></pre>
  
  <p>(notice the word head is missing)</p>
  
  <p>I can't figure out the problem. Any help would be appreciated :)</p>
  
  <pre><code>//ConvertToLowerCase class
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.IOException;
  public class CovertToLowerCase extends FileInputStream { //inherits from FileInputStream
  
  public CovertToLowerCase(String name) throws FileNotFoundException {
      super(name);
      // TODO Auto-generated constructor stub
  }
  
  
  public int read() throws IOException {
      char c=(char) super.read(); //calling the super method read
      c=Character.toLowerCase(c);
      return c;   
  }
  
  }
  
  import java.io.FileOutputStream;
  import java.io.FileNotFoundException;
  import java.io.IOException;
  
  public class HW4ex2 {
  
  public static void main(String[] args) throws FileNotFoundException {
      CovertToLowerCase c1=null;
      FileOutputStream output=null;
  
      try {
  
  
   c1= new CovertToLowerCase("C:/Users/user/workspace/HW4ex2/in.txt");
       output= new FileOutputStream("C:/Users/user/workspace/HW4ex2/out.txt");
          int a;
          while ((a=c1.read()) != -1)
          {
              System.out.print(a);
              output.write(a);
  
          }
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
      }
  
  }
  </code></pre>