<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">High level ones:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> s = </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">try</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">String</span><span style="font-variant-ligatures: no-common-ligatures" class="">(contentsOfFile: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">filename</span><span style="font-variant-ligatures: no-common-ligatures" class="">, encoding: .</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">utf8</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">try</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">s</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">write</span><span style="font-variant-ligatures: no-common-ligatures" class="">(toFile: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">filename</span><span style="font-variant-ligatures: no-common-ligatures" class="">, atomically: </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">true</span><span style="font-variant-ligatures: no-common-ligatures" class="">, encoding: .</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">utf8</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div></div><div class=""><br class=""></div><div class="">Low level ones:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">import</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Foundation</span></div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class=""><br class=""></span></p><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> fileManager = </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">FileManager</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">default</span><span style="font-variant-ligatures: no-common-ligatures" class="">()</span></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">guard</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> enumerator = </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">fileManager</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">enumerator</span><span style="font-variant-ligatures: no-common-ligatures" class="">(atPath: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">path</span><span style="font-variant-ligatures: no-common-ligatures" class="">) </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">else</span><span style="font-variant-ligatures: no-common-ligatures" class=""> { </span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">fatalError</span><span style="font-variant-ligatures: no-common-ligatures" class="">() }</span></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> !</span><span style="font-variant-ligatures: no-common-ligatures" class="">fileManager</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">fileExists</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(atPath: </span><span style="font-variant-ligatures: no-common-ligatures" class="">filename</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">) {</span></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">fileManager</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">createFile</span><span style="font-variant-ligatures: no-common-ligatures" class="">(atPath: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">filename</span><span style="font-variant-ligatures: no-common-ligatures" class="">, contents: </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">nil</span><span style="font-variant-ligatures: no-common-ligatures" class="">, attributes: </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">nil</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">guard</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> outFile = </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">FileHandle</span><span style="font-variant-ligatures: no-common-ligatures" class="">(forWritingAtPath: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">filename</span><span style="font-variant-ligatures: no-common-ligatures" class="">) </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">else</span><span style="font-variant-ligatures: no-common-ligatures" class=""> { </span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">fatalError</span><span style="font-variant-ligatures: no-common-ligatures" class="">() }</span></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">defer</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {</span></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; outFile.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">closeFile</span><span style="font-variant-ligatures: no-common-ligatures" class="">()</span></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">outFile.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">truncateFile</span><span style="font-variant-ligatures: no-common-ligatures" class="">(atOffset: </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">guard</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> data = </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">str</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">data</span><span style="font-variant-ligatures: no-common-ligatures" class="">(using: .</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">utf8</span><span style="font-variant-ligatures: no-common-ligatures" class="">) </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">else</span><span style="font-variant-ligatures: no-common-ligatures" class=""> { </span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">fatalError</span><span style="font-variant-ligatures: no-common-ligatures" class="">() }</span></p>
<p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">outFile.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">write</span><span style="font-variant-ligatures: no-common-ligatures" class="">(data)</span></p></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><br class=""></div><div class="">This used to work on Linux.</div><div class=""><br class=""></div><div class="">
<div class="">Andrey</div><br class="Apple-interchange-newline">

</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On 17 Jul 2016, at 02:33, K Richard Pixley via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class="">
  

    <meta http-equiv="content-type" content="text/html; charset=utf-8" class="">
  
  <div text="#000000" bgcolor="#FFFFFF" class="">
    I'm a new swift person, <i class="">long</i> time unix/linux developer, mac
    user but only mac developer inasmuch as mac is unix.&nbsp; I've installed
    swift on my ubuntu box, written hello world, etc.<br class="">
    <br class="">
    Now... to write much of anything else, I need a way to
    open/read/write/close a file.&nbsp; I don't see anything like that in the
    swift standard library, (aside from print()).&nbsp; And I don't see
    anything in the way of documentation for the Core Library.<br class="">
    <br class="">
    How do I do i/o in swift?<br class="">
    <br class="">
    I'm not thinking in terms of "an app", just a simple, read from
    stdin, write to stdout filter.&nbsp; How?<br class="">
    <br class="">
    Pointers welcome.<br class="">
    <br class="">
    --rich<br class="">
  </div>

_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></blockquote></div><br class=""></body></html>