Character Input/Output Stream

fileReader.java


	
/*
	
import java.io.FileReader;
import java.io.IOException;

/* Implementing "FileReader" class
1. class FileReader extends InputStreamReader
2. This class implements a character input stream, or file reader,
   for reading characters from a file
3. To read characters from a file, create a FileReader using its filename.

   FileWriter class works in a similar manner.
*/

class myFileReader
{
     public static void main(String args[])
     {
	    // The number of arguments to be expected from the command line
	if (args.length != 1) 
	{
	   System.err.println("Usage: java myFileReader ");
           System.exit(0);
        }
	try 
	{
           int count, i = 1;
	   final int maxChars = 32;
	   char buffer[] = new char[maxChars];

	   // Create file a FileReader Object
	   FileReader fR = new FileReader(args[0]);
	   System.out.println(fR.markSupported()?"Mark is suppoertd":"Mark is not supported");		
           while ((count = fR.read(buffer)) >= 0)
	   {
	   	  System.out.print("Buffer " + i++ + ": " );
		  for (int j = 0; j < count; j++)
			System.out.print(buffer[j]);
		  System.out.println("\n");	  
	   }      
	}
	catch(IOException e)
	{
	    e.printStackTrace();
	}
	catch(ArrayIndexOutOfBoundsException e)
	{
	    e.printStackTrace();
	}
    }
}

  

Back to Character Input Stream

Go Back to Input/Output