Results 1 to 6 of 6

Thread: Reading a file as a whole string.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Resolved Reading a file as a whole string.

    I can't seem to find it on the net. Is there a way to just say

    String s = someReader.ReadToEnd();

    like the on in C#, all I have seen so far is the reading per line. Help anyone? Thanks!
    Last edited by nebulom; Mar 13th, 2007 at 06:36 PM.

  2. #2
    Addicted Member TBeck's Avatar
    Join Date
    Apr 2006
    Location
    Ontario, Canada
    Posts
    254

    Re: Reading a file as a whole string.

    i dont know about a function to for reading all of it as a string but you can keep adding the new lines to the same string.

  3. #3
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Reading a file as a whole string.

    You can make your own method with a StringBuffer, I guess. But there's nothing in the API to do what you want.

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Reading a file as a whole string.

    But there is in the Springframework utilities or the Apache Jakarta Commons IO.

    Springframework is too big to use unless you use its main facilities, but Commons IO is nice and small and a good addition.
    http://jakarta.apache.org/commons/io...ase/index.html
    Code:
    String data = IOUtils.toString(new FileInputStream(filename), "UTF-8");
    Hey, SysError, are you making fun of penagate?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Reading a file as a whole string.

    Quote Originally Posted by CornedBee

    Hey, SysError, are you making fun of penagate?
    I wasn't, but after the many personal attacks a few weeks ago, I like to think so now.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: Reading a file as a whole string.

    Thanks everyone.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width