473,387 Members | 1,282 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

What is the difference between BufferedReader and InputStreamReader

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


Thanks 2 all repliers
sravan
Feb 26 '10 #1
2 11683
jkmyoung
2,057 Expert 2GB
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 InputStreamReader class"
Feb 26 '10 #2
To read keys from the keyboard, you usually construct an InputStreamReader stream from System.in and then use the InputStreamReader class’s read method to read what the user has typed.
For Example--

Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. public class inputstreamreader
  3. {
  4.     public static void main(String args[]) throws IOException 
  5.     {    
  6.         char[] c=new char[10];        
  7.         InputStreamReader isr=new InputStreamReader(System.in);
  8.         isr.read(c,0,9); 
  9.         for(int i=0;i<c.length;i++)
  10.             System.out.print((char)c[i]);
  11.         isr.close();
  12.     }
  13. }
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--

Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. public class bufferedreader
  3. {
  4.     public static void main(String args[]) throws IOException 
  5.     {
  6.         FileReader fr=new FileReader("bufferedreader.java");
  7.         BufferedReader br=new BufferedReader(fr);
  8.         String str;
  9.         while((str=br.readLine())!=null)
  10.             System.out.println(str);
  11.         fr.close();
  12.     }
  13. }
Feb 27 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: foo | last post by:
I've been looking on the web to see if I could find a link that would describe the difference between the 14882:1998 and the 14882:2003 C++ standard. I found the following link:...
2
by: diadia | last post by:
string s = "hello"; const char *p = s.begin(); cout << p << endl; // print hello s = ""; char *p2= s.begin(); cout << p2 << endl; // print hello why?????
48
by: Wade Yin | last post by:
Hi, What's the difference between: char *x="abcde"; and char y={"abcde"};
11
by: J Wang | last post by:
dear, I debug the program recently as follows. #include <sys/stat.h> int main(int argc, char *argv) { struct stat buf;
0
by: programer | last post by:
Can I use Activex (as vb) to connect database when I use vc.net.
2
by: ajay.bansal02 | last post by:
Hi All What is difference in TCHAR myVar=.....; and TCHAR *myVAR1=(TCHAR *)malloc....; arent both myVar and myVAR1are same?
4
by: Dennis | last post by:
I am trying to set up an Expression column in a DataTable for display in a DataGrid that subtract the column ("BirthDay") from todays date. I can't seem to get it right...is this possible? --...
0
by: RupeshDeenadayalan | last post by:
Is there any difference between a boot loader and a boot strapper.It would be better if any one can tell what operations does a general bootloader,boot strapper,BSP,Driver does???
2
by: martin paul | last post by:
Hello Sir...Could you tell me the KEY difference between signal and sigaction functions....Kindly consider the following sample program which is using signal function... #include <signal.h> void...
5
by: bhushanbagul | last post by:
Hi All Please let me know exactly what difference i and g makes in oracle version i.e. when we say oracle 10g or oracle 11i Thanks Bhushan
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.