REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 3-Aug-2010 Edit History  

REBOL 3 Functions: read

read  source  /part  length  /seek  index  /string  /lines

Read from a file, URL, or other port.

Arguments:

source [port! file! url! block!]

Refinements:

/part - Partial read a given number of units (source relative)

length [number!]

/seek - Read from a specific position (source relative)

index [number!]

/string - Convert UTF and line terminators to standard text string

/lines - Convert to block of strings (implies /string)

See also:

write   open   close   load   save  

Description

Using READ is the simplest way to get information from a file or URL. This is a higher level port operation that opens a port, reads some or all of the data, then closes the port and returns the data that was read. When used on a file, or URL, the contents of the file, or URL are returned as a string.

The /LINES refinement returns read content as a series of lines. One line is created for each line terminator found in the read data.

The /PART refinement reads the specified number of elements from the file, URL, or port. Reading a file or URL will read the specified number of characters. Used with /LINES, it reads a specified number of lines.

See the User's Guide for more detailed explanation of using READ and its refinements.

write %rebol-test-file.r "text file"
print read %rebol-test-file.r
read
write %rebol-test-file.r [
{A learned blockhead is a greater man
than an ignorant blockhead.
    -- Rooseveldt Franklin}
]
probe first read/lines %rebol-test-file.r
write
probe pick (read/lines %rebol-test-file.r) 3

probe read/part %rebol-test-file.r 9

probe read/with %rebol-test-file.r "blockhead"
write/append %matrix.avi to-binary "abcdefg"


  TOC < Back Next > REBOL.com - WIP Wiki Feedback Admin