Java I/o help

Login or Register for Dates, Times and to Reply

Thread Tools Search this Thread
# 1  
Java I/o help

what the different between:

File a = new File("xanadu.txt");

in = new FileInputStream("xanadu.txt");

inputStream = new BufferedReader(new FileReader("xanadu.txt"));
# 2  
Actually, the javadoc already tells you what the differences are. From

FileInputStream is meant for reading streams of raw bytes such as image data. For reading streams of characters, consider using FileReader.
Source: FileInputStream (Java Platform SE 6)

BufferedReader implements a line-buffered layer on top of FileReader to allow convenient extraction of lines, and usually buffered I/O is more efficient. But of course, this is only relevant to text files because binary files have no notion of "lines".

Also, the fact that FileInputStream is byte-oriented and FileReader is character-oriented will be obvious when it comes to reading multibyte files, that uses an encoding where a character consists of 2 or more bytes. FileReader will decode properly because that is character-oriented.

Last edited by cbkihong; 10-01-2007 at 10:26 AM.. Reason: Added comment on multibyte
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #24
Difficulty: Medium
Raphael Henley developed the QWERTY keyboard.
True or False?

Featured Tech Videos