Read All File Lines

From SwiftAPI

Jump to: navigation, search

Read all of the lines from a file into an array.

Contents

Perl

open $fh, $filePath;
@lines = <$fh>;
close $fh;

PHP

php.net

array file ( string $filename [, int $flags = 0 [, resource $context ]] )
$lines = file($filePath);

Python

docs.python.org

contents = open(filePath).readlines()

Ruby

contents = File.readlines(filePath)
Personal tools