File as a String object

Discussion in 'Java' started by zku, Jul 30, 2003.

  1. zku

    zku Guest

    Hi,

    I am trying to make a String object from a text file.

    String text = ... the file's content.

    as the file has " and \n and \ characters.

    the String object is not proper created.

    Any idea how?

    tia
     
    zku, Jul 30, 2003
    #1
    1. Advertising

  2. On Wed, 30 Jul 2003 16:26:01 +0800, zku wrote:
    > I am trying to make a String object from a text file.
    >
    > String text = ... the file's content.
    >
    > as the file has " and \n and \ characters.
    >
    > the String object is not proper created.


    What exactly did you try? What kind of errors were there in the String
    contents?

    > Any idea how?


    Open the file with a FileInputStream and an InputStreamReader. Read
    the file into e.g. a StringBuffer. After you reach the end of the
    file, create a String from the StringBuffer.

    /gordon

    --
    [ do not send me private copies of your followups ]
    g o r d o n . b e a t o n @ e r i c s s o n . c o m
     
    Gordon Beaton, Jul 30, 2003
    #2
    1. Advertising

  3. zku

    Roedy Green Guest

    Roedy Green, Jul 30, 2003
    #3
    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.

Share This Page