• Post Reply Bookmark Topic Watch Topic
  • New Topic

Files I/O

 
Angela D'souza
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is difference between FileInputStream, DataInputStream Vs.FileReader Vs. BufferedReader Vs.RandomFileAccess?
Thanks,
angela
 
Zakaria Haque
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Angela D'souza:
What is difference between FileInputStream, DataInputStream Vs.FileReader Vs. BufferedReader Vs.RandomFileAccess?
Thanks,
angela

FileInputStream: use it to read from files.
DataInputStream: implements DataInput interface which has convenient methods to read primitive data types. If you have to read String, and the String was not written to the Stream using some DataOutput implementation (like DataOutputStream) you may have trouble.
FileReader: similar to FileInputStream, but you should use it only to read character streams. If the file has binary data, use FileInputStream instead.
BufferedReader: implements FilterReader, that is, it works like a decorator around another Reader object. buffers data, which may increase performance.
RandomAccessFile: gives a array like view of the file, where you can move around the file arbitrarily, similar to the way C library handles files. implements DataInput and DataOutput.

See the api spec for further inormation @
http://java.sun.com/j2se/1.3/docs/api/index.html
Hope it helps.
 
Soumendu Munshi
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, you can refer to Java tutorial at Sun web site for this. They have nice and detailed explanation for this. In short they divided reading and writeing operation for BINARY (JPEG, GIF, EXE etc.) file and Text file. What it seems that anyt method that has STREAM is meant for binary operation and rest for text. Hope this helps a bit
refer following link for detail.
http://java.sun.com/docs/books/tutorial/essential/io/datasinks.html
Soum.
 
Angela D'souza
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all,
I read some documents on I/O. I want to clear it:
Java I/O package has main classes :
-InputStream/OutputStream
-RandomAccessFile
-FileDiscriptor
-File
-Reader/Writer
Subclasses of InputStream/OutputStream are
-FileInputStream/FileOutputStream
-FilterInputStream/FilterOutputStream
Subclasses of FilterInputStream/FilterOutputStream are
-DataInputStream/DataOutputStream

(1)File classe use for Creating/deleting/renaming files.
(2)FileInputputStream/FileoutputStream use to read/write streams(bytes) to the files.
(3)DataInputStream/DataoutputStream use to read Java primitive data types.
(4)RandomAccessFile use to write bytes anywhere in this file. Also use to read read only file.
(5) Reader/Writer use for unicode characters.
(6) FilterInputStream use to read other streams.
AM I WRONG ANYWHERE IN ABOVE DESCRIPTION? AND ALSO WHAT HAPPENS IF I DON'T USE DataInput/output streams.
Thanks again,
Angela
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!