c++ to Java question

Discussion in 'Java' started by Ike, Jan 19, 2004.

  1. Ike

    Ike Guest

    Suppose 'ar' is a fileoutputstream, and 'label' is a String.

    How would the following line be performed by us, in Java:

    ar << " '" << label << "', "

    Thanks, Ike
    Ike, Jan 19, 2004
    #1
    1. Advertising

  2. Ike <> scribbled the following:
    > Suppose 'ar' is a fileoutputstream, and 'label' is a String.


    > How would the following line be performed by us, in Java:


    > ar << " '" << label << "', "


    > Thanks, Ike


    ar.write("'"+label+", ")

    --
    /-- Joona Palaste () ------------- Finland --------\
    \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
    "'I' is the most beautiful word in the world."
    - John Nordberg
    Joona I Palaste, Jan 19, 2004
    #2
    1. Advertising

  3. Ike

    Jon A. Cruz Guest

    Joona I Palaste wrote:
    >>How would the following line be performed by us, in Java:

    >
    >
    >> ar << " '" << label << "', "

    >
    >
    >>Thanks, Ike

    >
    >
    > ar.write("'"+label+", ")
    >


    Or it's often more appropriate to use MessageFormat. That gives you
    formatting, internationalizeation, easy changing of user-friendly text, etc.

    ar.write( MessageFormat.format( "'{0}, ", new Object[]{label} ) );
    Jon A. Cruz, Jan 19, 2004
    #3
  4. Joona I Palaste <> wrote:

    > Ike <> scribbled the following:
    >> Suppose 'ar' is a fileoutputstream, and 'label' is a String.

    >
    >> How would the following line be performed by us, in Java:

    >
    >> ar << " '" << label << "', "

    >
    >> Thanks, Ike

    >
    > ar.write("'"+label+", ")


    InputStream doesn't accept Strings, so I guess you meant

    ar.write((" '" + label + ", ").getBytes(/* charset name */));

    --
    No address munging in use. I like the smell of nuked accounts in the
    morning.
    Timo Kinnunen, Jan 19, 2004
    #4
  5. Timo Kinnunen <> scribbled the following:
    > Joona I Palaste <> wrote:
    >> Ike <> scribbled the following:
    >>> Suppose 'ar' is a fileoutputstream, and 'label' is a String.

    >>
    >>> How would the following line be performed by us, in Java:

    >>
    >>> ar << " '" << label << "', "

    >>
    >>> Thanks, Ike

    >>
    >> ar.write("'"+label+", ")


    > InputStream doesn't accept Strings, so I guess you meant


    > ar.write((" '" + label + ", ").getBytes(/* charset name */));


    Of course, assuming you meant OutputStream and not InputStream. =)

    --
    /-- Joona Palaste () ------------- Finland --------\
    \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
    "Remember: There are only three kinds of people - those who can count and those
    who can't."
    - Vampyra
    Joona I Palaste, Jan 19, 2004
    #5
  6. Joona I Palaste <> wrote:

    > Timo Kinnunen <> scribbled the following:
    >> InputStream doesn't accept Strings, so I guess you meant

    >
    >> ar.write((" '" + label + ", ").getBytes(/* charset name */));

    >
    > Of course, assuming you meant OutputStream and not InputStream. =)


    Of course :)

    --
    No address munging in use. I like the smell of nuked accounts in the
    morning.
    Timo Kinnunen, Jan 20, 2004
    #6
  7. Ike

    CN Guest

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    It makes no difference here, unless you store the "'{0}, " in some
    resource bundle.

    Jon A. Cruz wrote:
    | Joona I Palaste wrote:
    |
    |>> How would the following line be performed by us, in Java:
    |>
    |>
    |>
    |>> ar << " '" << label << "', "
    |>
    |>
    |>
    |>> Thanks, Ike
    |>
    |>
    |>
    |> ar.write("'"+label+", ")
    |>
    |
    | Or it's often more appropriate to use MessageFormat. That gives you
    | formatting, internationalizeation, easy changing of user-friendly text,
    | etc.
    |
    | ar.write( MessageFormat.format( "'{0}, ", new Object[]{label} ) );
    |
    |
    |

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.4 (GNU/Linux)
    Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

    iD8DBQFAdlcAgtM42grMkd0RArHfAJ48pes5CAmZIUUMJ54mwNl9IK1I8gCeNpkK
    xnfFx1Gu7IfxX6/1tx074uU=
    =AVW7
    -----END PGP SIGNATURE-----
    CN, Apr 9, 2004
    #7
    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. Michael Kintner
    Replies:
    0
    Views:
    835
    Michael Kintner
    Nov 30, 2003
  2. Peter
    Replies:
    1
    Views:
    532
    Chris Smith
    Jan 9, 2005
  3. Ilias Lazaridis
    Replies:
    0
    Views:
    552
    Ilias Lazaridis
    Feb 1, 2005
  4. manish sahu
    Replies:
    3
    Views:
    990
  5. Isaac
    Replies:
    0
    Views:
    354
    Isaac
    Jan 20, 2011
Loading...

Share This Page