Read Entire File

From SwiftAPI

Jump to: navigation, search

Contents

C#

using System.IO;
string contents = File.ReadAllText(filePath);

Objective-C

developer.apple.com

NSData *contents = [NSData dataWithContentsOfFile:filePath];

Perl

See this FAQ entry

open $fh, $filePath;
$contents = do { local( $/ ); <$fh> };
close $fh;

Using the third-party File::Slurp module:

use File::Slurp;
$contents = read_file($filePath);

PHP

php.net

$contents = file_get_contents($filePath);

Python

docs.python.org

contents = open(filePath).read()

Ruby

contents = File.read(filePath)
Personal tools