I am barely learning Java and so far I have come across multiple
classes you can use for File I/O....
Which classes are most frequently used or preferred?
For example
FileOutputStream or FileWriter
FileInputStream or FileReader
Should I use BufferedReader? Is it necessary?
I know it depends on what is needed, but what is the most commonly used
classes for most programmers.
Thank you,
Paul
Knute Johnson - 27 Sep 2006 21:15 GMT
> I am barely learning Java and so far I have come across multiple
> classes you can use for File I/O....
[quoted text clipped - 13 lines]
> Thank you,
> Paul
Readers for text, streams for bytes. Buffer as necessary for performance.

Signature
Knute Johnson
email s/nospam/knute/
Thomas Weidenfeller - 28 Sep 2006 10:34 GMT
> I am barely learning Java and so far I have come across multiple
> classes you can use for File I/O....
>
> Which classes are most frequently used or preferred?
It is not a question about preference. It is a question about a class
doing what you need or not.
> I know it depends on what is needed, but what is the most commonly used
> classes for most programmers.
It does not matter what that class might be. If it is not the right one
*for your application* it will not work for you.
Go, learn the properties and function of the classes and then select the
ones which do what you need, not the ones which happen to work in other
people applications.
/Thomas

Signature
The comp.lang.java.gui FAQ:
http://gd.tuwien.ac.at/faqs/faqs-hierarchy/comp/comp.lang.java.gui/
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
Josh Falter - 28 Sep 2006 20:59 GMT
The most common and simplest way to read files is to use a
BufferedReader, which I think goes something like
BufferedReader br = new BufferedReader(new FileReader(new
File(filename)));
String st = br.readLine();
while(st != null)
{
//process data
st = br.readLine();
}
br.close();
that may not be the exact syntax, but it is close enough to get you
started reading simple text files
Arne Vajhøj - 30 Sep 2006 21:13 GMT
> I am barely learning Java and so far I have come across multiple
> classes you can use for File I/O....
[quoted text clipped - 10 lines]
> I know it depends on what is needed, but what is the most commonly used
> classes for most programmers.
Reader/Writer - for text
InputStream/OutputStream - for binary bytes or as basis for others
DataInputStream/DataOutputStream - for binary simple data types
ObjectInputStream/ObjectOutputStream - for binary Java objects
You use buffered if you read/write small chunks of data and
needs good performance.
Arne