On Sun, Sep 9, 2012 at 3:56 AM, justay w <
wr2...@gmail.com> wrote:
> hi ,
>
> I got a other question about ReadString
> if my file have many lines, how can i read out them all using ReadString
> i try to use: ReadString('\n') just read the firstline.
> ths for help.
You can continually call ReadString('\n') to read more strings. Here
is a toy example:
http://itsapad.appspot.com/288002. It reads all
lines from a file called "tmp.go" and prints them preceded by their
line number (starting with 0). The readLines function is what you
want, it returns all lines read from the given reader in a slice.
Remember to be careful when reading in entire files like this,
however, because if you don't necessarily trust the source then they
can easily eat up all of your memory.
Best,
Ethan