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

Discussion in 'Java' started by m.cantaloupe, May 13, 2004.

  1. m.cantaloupe

    m.cantaloupe Guest

    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.
    m.cantaloupe, May 13, 2004
    #1
    1. Advertising

  2. m.cantaloupe

    Sudsy Guest

    m.cantaloupe wrote:
    > 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?
    Sudsy, May 13, 2004
    #2
    1. Advertising

  3. m.cantaloupe wrote:
    > 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)?
    Michael Borgwardt, May 13, 2004
    #3
  4. m.cantaloupe

    m.cantaloupe Guest

    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.

    Sudsy <> wrote in message news:<>...
    > m.cantaloupe wrote:
    > > 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.cantaloupe, May 14, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andres Montiel

    [wee bit OT] UML tutorials

    Andres Montiel, Sep 5, 2003, in forum: Python
    Replies:
    1
    Views:
    300
    Alan Gauld
    Sep 5, 2003
  2. pkirk25
    Replies:
    5
    Views:
    377
    pkirk25
    Oct 24, 2006
  3. JimLad
    Replies:
    5
    Views:
    676
    Pavel Lepin
    Jul 11, 2007
  4. rob lynch
    Replies:
    2
    Views:
    116
    rob lynch
    Mar 10, 2006
  5. Mark
    Replies:
    5
    Views:
    174
    Kyle T. Jones
    Dec 2, 2011
Loading...

Share This Page