title: downcasting and upcasting in java file io?
body: <p>For writing a string of data into a file using fileoutputstream we go for converting for string into byte array.For reading a string of data using fileinputstream we can't use convertion.
  what is the reason for that?</p>
  
  <p>reading:</p>
  
  <pre><code>class Test {
    public static void main(String args[]) {
      try {
        Fileinputstream fin = new Fileinputstream("abc.txt");
        int i = 0;
        while ((i = fin.read()) != -1) {
          System.out.print((char) i);
        }
        fin.close();
      } catch (Exception e) {
        System.out.println(e);
      }
    }
  }
  </code></pre>
  
  <p>writing:</p>
  
  <pre><code>class Test {
    public static void main(String args[]) {
      try {
        FileOutputstream fout = new FileOutputStream("abc.txt");
        String s = "Sachin Tendulkar is my favourite player";
        byte b[] = s.getBytes(); //converting string into byte array
        fout.write(b);
        fout.close();
        System.out.println("success...");
      } catch (Exception e) {
        system.out.println(e);
      }
    }
  }
  </code></pre>