IO Streams... I'm a wee bit confused here - any help appreciated.

M

m.cantaloupe

I've tried to simplify my question as much as possible, so here we go:

If the PrintWriter class accepts and OutputStream object as an
argument, then why won't this work:
serverOut = new PrintWriter(connection.getOutputStream());

Instead I am forced to use:
serverOut = new PrintStream(connection.getOutputStream());

.... but I can't figure why. Anybody care to shed some light?

Cheers,

Marc.
 
S

Sudsy

m.cantaloupe said:
I've tried to simplify my question as much as possible, so here we go:

If the PrintWriter class accepts and OutputStream object as an
argument, then why won't this work:
serverOut = new PrintWriter(connection.getOutputStream());

Instead I am forced to use:
serverOut = new PrintStream(connection.getOutputStream());

... but I can't figure why. Anybody care to shed some light?

And we don't know the semantics of your connection object. What class
is it? What do the javadocs say about the class returned by the
getOutputStream method?
 
M

Michael Borgwardt

m.cantaloupe said:
I've tried to simplify my question as much as possible, so here we go:

If the PrintWriter class accepts and OutputStream object as an
argument, then why won't this work:
serverOut = new PrintWriter(connection.getOutputStream());

How exactly does it "not work" (it should)?
 
M

m.cantaloupe

Yeah, sorry about that. 'connection' is a java.net.Socket.
'getOutputStream()' returns an 'OutputStream' object. Hence the
confusion, as PrintWriter definitely has a constructor that accepts a
PrintStream.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top