Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2006

Tip: Looking for answers? Try searching our database.

File I/O....which class to use?

Thread view: 
Darth Tyrannus - 27 Sep 2006 20:50 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?

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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.