readlines

readlines(stream)

Read all lines as an array.

Examples

Read lines from a file

fp = open("numbers.txt");
foo = readlines(fp)     # can be a socket stream too, for example
5-element Array{Union(ASCIIString,UTF8String),1}:
"1\n"
"2\n"
"3\n"
"4\n"
"5\n"
  1. Read lines from a file:

    julia> file = open("data.txt", "r");
    julia> lines = readlines(file);
    julia> close(file);

    This example reads all lines from a file named "data.txt" and stores them in an array called lines. Don't forget to close the file after reading.

  2. Read lines from standard input (stdin):

    julia> lines = readlines(stdin);

    This example reads lines from the standard input (stdin) and stores them in the lines array.

Common mistake example:

julia> lines = readlines("data.txt");
ERROR: MethodError: no method matching readlines(::String)

In this example, the readlines function is used with a string argument instead of a file or stream. Make sure to provide a valid file or stream object as the argument to readlines.

See Also

abspath, basename, chmod, countlines, cp, ctime, dirname, download, evalfile, expanduser, fdio, filemode, filesize, functionloc, gperm, homedir, include_string, isabspath, isblockdev, ischardev, isdir, isdirpath, isexecutable, isfifo, isfile, islink, ismount, ispath, isreadable, issetgid, issetuid, issticky, iswritable, joinpath, less, lstat, mkdir, mkpath, mktemp, mktempdir, mtime, mv, normpath, operm, poll_fd, poll_file, readall, readcsv, readdir, readdlm, readlines, readlink, realpath, relpath, rm, splitdir, splitdrive, splitext, stat, symlink, tempdir, tempname, touch, truncate, uperm, watch_file, writecsv,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: