What is the difference between BufferedReader and InputStreamReader

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sravan008
    New Member
    • Feb 2010
    • 10

    #1

    What is the difference between BufferedReader and InputStreamReader

    guys can any one tell me what is the difference b/t BufferedReader and InputStreamRead er , i got one ans from this website but it's not clear so can any elaborate and answer plz


    Thanks 2 all repliers
    sravan
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    1. Specifically InputReader can covert bytes in different encodings to characters.
    --
    2. BufferedReader has a back-end reader which speeds up reading if you are only retrieving small parts at a time.
    3. BufferedReader can mark a given position, and after already reading the bytes, reset back to the previous position.


    Try googling "Java bufferedReader class" and "Java InputStreamRead er class"

    Comment

    • anurag275125
      New Member
      • Aug 2009
      • 79

      #3
      To read keys from the keyboard, you usually construct an InputStreamRead er stream from System.in and then use the InputStreamRead er class’s read method to read what the user has typed.
      For Example--

      Code:
      import java.io.*;
      public class inputstreamreader
      {
      	public static void main(String args[]) throws IOException 
      	{	
      		char[] c=new char[10];		
      		InputStreamReader isr=new InputStreamReader(System.in);
      		isr.read(c,0,9); 
      		for(int i=0;i<c.length;i++)
      			System.out.print((char)c[i]);
      		isr.close();
      	}
      }
      The BufferedReader class provides a buffered character reader class. One of its advantages is that BufferedReader provides the readLine method. This method reads the file line by line instead of character by character.

      for example--

      Code:
      import java.io.*;
      public class bufferedreader
      {
      	public static void main(String args[]) throws IOException 
      	{
      		FileReader fr=new FileReader("bufferedreader.java");
      		BufferedReader br=new BufferedReader(fr);
      		String str;
      		while((str=br.readLine())!=null)
      			System.out.println(str);
      		fr.close();
      	}
      }

      Comment

      Working...