Difference between revisions of "Code Snippet: Read File"

From Coder Merlin
Line 1: Line 1:
== Read the contents of a file into a string ==
= Read the contents of a file into a string =
 
== Swift ==
<syntaxhighlight lang="swift">
<syntaxhighlight lang="swift">
import Foundation
import Foundation
Line 5: Line 7:
let contents = try! String(contentsOfFile: "hello.txt")                                                                                                                                               
let contents = try! String(contentsOfFile: "hello.txt")                                                                                                                                               
</syntaxhighlight>
</syntaxhighlight>
== Python ==

Revision as of 17:50, 24 December 2018

Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder

Read the contents of a file into a string[edit]

Swift[edit]

import Foundation

let contents = try! String(contentsOfFile: "hello.txt")

Python[edit]