Monday 16 December 2013

the InputStream and OutputStream example using java


import java.io.*;
public class Main {

    /**
     * @param args the command line arguments
     */

   public static void main(String args[]){

   try{

     byte byWrite [] = {1,12,13,14,15};
     
     OutputStream out = new FileOutputStream("D://ReadFile.txt");

     for(int x=0; x < byWrite.length ; x++){
         out.write( byWrite[x] ); // writes the bytes
      }
      out.close();

      InputStream is = new FileInputStream("D://ReadFile.txt");
      int size = is.available();

      for(int i=0; i< size; i++){
         System.out.print((char)is.read() + "  ");
      }
      is.close();
   }catch(IOException e){
      System.out.print("Exception");
   }
   }
}

No comments:

Post a Comment

Comment