Could you please explain me what is a BufferedStream (what is a buffer and how it should be used?)? I have used a code that uses bufferedstream to write to a .txt file. I got the code while googling but don't know the theory behind how it works... please explain.

Usually Java has some tutorials on this over their website: Click Here
Full tutorial: Click Here

this might be a good place for you to start searching

commented: Same as my link ;) +7

I have gone through the tutorials... Thanks for the link... But i never understood the meaning of buffer(I am sure there is a logic behind its being called as "BufferStreams" and not anything else..)

Does it mean that using BufferedStreams should always be preferred over using unbuffered streams as we don't have to call upon the native API many times for reading and writing.. is there any particular example where unbuffered streams are preferred over buffered streams..?

Use unbuffered output streams when you want each write to be processed immediately - eg Writing a log file - you don't want the last few messages to be lost when the program crashes and the buffer is lost. Another eg - writing to a network stream to send chat messages to another PC - you want each message to be sent immediately, you don't want them stored up until there is a complete buffer-full to be sent.
I can't think of any cases where you would prefer an unbuffered input stream

As for why it's called a "buffer" - have a look at some of the many other uses for that word and you'll see how the concept fits: http://en.wikipedia.org/wiki/Buffer

oh.. thanks a lot James, Stultuske... i am learning a lot from you guys... i think i will be a decent programmer in 4-5 months if i could keep in touch with you guys and keep learning from you... Thanks :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.