title: Read and write a String from text file
body: <p>I need to read and write data to/from a text file, but I haven't been able to figure out how.</p>
  <p>I found this sample code in the Swift's iBook, but I still don't know how to write or read data.</p>
  <pre><code>import Cocoa
  
  class DataImporter {
      /*
      DataImporter is a class to import data from an external file.
      The class is assumed to take a non-trivial amount of time to initialize.
      */
      var fileName = &quot;data.txt&quot;
      // the DataImporter class would provide data importing functionality here
  }
  
  class DataManager {
      @lazy var importer = DataImporter()
      var data = String[]()
      // the DataManager class would provide data management functionality here
  }
  
  let manager = DataManager()
  manager.data += &quot;Some data&quot;
  manager.data += &quot;Some more data&quot;
  // the DataImporter instance for the importer property has not yet been created”
  
  println(manager.importer.fileName)
  // the DataImporter instance for the importer property has now been created
  // prints &quot;data.txt”    
  
  var str = &quot;Hello World in Swift Language.&quot;
  </code></pre>