Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #9184

I/O Confusion

From Novice <novice@example..com>
Newsgroups comp.lang.java.programmer
Subject I/O Confusion
Date 2011-10-25 23:12 +0000
Organization Your Company
Message-ID <Xns9F89C3FFB48DDjpnasty@94.75.214.39> (permalink)

Show all headers | View raw


I'm try to wrap my head around the basic I/O classes, especially how to 
choose the one I need for a given job. 

I understand that Streams are for bytes and Readers and Writers are for 
characters and I think I understand the distinction between bytes and 
characters.  

Let's say that I want to write characters, as opposed to bytes. How do I 
decide which subclass of Writer I want to use? I'm not clear on when 
BufferedWriter, say, is preferable to PrintWriter. 

I also get very confused when I see Streams, Readers and Writers wrapped 
within one another. For example, this snippet confuses me:

Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream
("outfilename"), "UTF8"));

Why wrap FileOutputStream within OutputStreamWriter within BufferedWriter? 
Why not just BufferedWriter, say, to do everything? What is actually 
happening at execution time when you execute this code? 

Also, when do I use this basic I/O and when is it better to use the NIO 
classes? 

I've looked at a few different tutorials but the penny hasn't dropped for 
me yet. Any advice on how to answer these questions for myself?

-- 
Novice

Back to comp.lang.java.programmer | Previous | NextNext in thread | Find similar


Thread

I/O Confusion Novice <novice@example..com> - 2011-10-25 23:12 +0000
  Re: I/O Confusion Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-10-25 21:20 -0400
  Re: I/O Confusion Silvio Bierman <silvio@moc.com> - 2011-10-26 03:21 +0200
  Re: I/O Confusion markspace <-@.> - 2011-10-25 18:47 -0700
  Re: I/O Confusion Roedy Green <see_website@mindprod.com.invalid> - 2011-10-26 08:55 -0700
    Re: I/O Confusion "Nasser M. Abbasi" <nma@12000.org> - 2011-10-26 12:03 -0500
      Re: I/O Confusion Novice <novice@example..com> - 2011-10-26 17:35 +0000
    Re: I/O Confusion Novice <novice@example..com> - 2011-10-26 20:57 +0000
      Re: I/O Confusion Roedy Green <see_website@mindprod.com.invalid> - 2011-10-26 16:48 -0700

csiph-web