Write Entire File

From SwiftAPI

Jump to: navigation, search

Contents

Objective-C

NSString *contents = @"Hello World";
NSString *filePath = @"file.txt";
[contents writeToFile:filePath atomically:NO encoding:NSUTF8StringEncoding error:NULL];

PHP

$contents = 'Hello World';
$filePath = 'file.txt';
file_put_contents($filePath, $contents);

Python

contents = "Hello World"
filePath = "file.txt"
f = open(filePath, "w")
f.write(contents)
f.close()

Ruby

contents = "Hello World"
filePath = "file.txt"
File.open(filePath, 'w') do |f|
    f.write contents
end
Personal tools