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. Advertisements

  2. m.cantaloupe

    Sudsy Guest

    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. Advertisements

  3. 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.
     
    m.cantaloupe, May 14, 2004
    #4
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.