|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang=" en-US"> |
| 3 | +<head> |
| 4 | + <meta charset="utf-8"> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"> |
| 6 | + |
| 7 | + <link rel="shortcut icon" type="image/x-icon" href="/assets/images/favicon.ico"> |
| 8 | + |
| 9 | + <link rel="stylesheet" href="/assets/css/style.css?v=eefd67c39c36d58b99451ccfef07bda8356bf95e"> |
| 10 | + |
| 11 | + <script src="/assets/js/image_titler.js"></script> |
| 12 | + <script src="/assets/js/scale.fix.js"></script> |
| 13 | + |
| 14 | + <script defer data-domain="sampleprograms.io" src="https://plausible.io/js/plausible.js"></script> |
| 15 | + |
| 16 | + <link type="application/atom+xml" rel="alternate" href="https://sampleprograms.io/feed.xml" title="Sample Programs in Every Language" /> |
| 17 | + |
| 18 | + |
| 19 | +<!-- Twitter cards --> |
| 20 | +<meta name="twitter:title" content="File Input Output in Elixir"> |
| 21 | +<meta name="twitter:description" content=""> |
| 22 | + |
| 23 | +<meta name="twitter:card" content="summary_large_image"> |
| 24 | +<meta name="twitter:image" content="https://sampleprograms.io/assets/images/file-input-output-in-every-language.jpg"> |
| 25 | +<!-- end of Twitter cards --> |
| 26 | + <!-- Begin Jekyll SEO tag v2.8.0 --> |
| 27 | +<title>File Input Output in Elixir | Sample Programs in Every Language</title> |
| 28 | +<meta name="generator" content="Jekyll v3.10.0" /> |
| 29 | +<meta property="og:title" content="File Input Output in Elixir" /> |
| 30 | +<meta name="author" content="Ricardo Mapurunga Junior" /> |
| 31 | +<meta property="og:locale" content="en_US" /> |
| 32 | +<meta name="description" content="A Collection of Code Snippets in as Many Programming Languages as Possible" /> |
| 33 | +<meta property="og:description" content="A Collection of Code Snippets in as Many Programming Languages as Possible" /> |
| 34 | +<link rel="canonical" href="https://sampleprograms.io/projects/file-input-output/elixir/" /> |
| 35 | +<meta property="og:url" content="https://sampleprograms.io/projects/file-input-output/elixir/" /> |
| 36 | +<meta property="og:site_name" content="Sample Programs in Every Language" /> |
| 37 | +<meta property="og:type" content="article" /> |
| 38 | +<meta property="article:published_time" content="2026-05-28T00:00:00+00:00" /> |
| 39 | +<meta name="twitter:card" content="summary" /> |
| 40 | +<meta property="twitter:title" content="File Input Output in Elixir" /> |
| 41 | +<script type="application/ld+json"> |
| 42 | +{"@context":"https://schema.org","@type":"BlogPosting","author":{"@type":"Person","name":"Ricardo Mapurunga Junior"},"dateModified":"2026-05-28T00:00:00+00:00","datePublished":"2026-05-28T00:00:00+00:00","description":"A Collection of Code Snippets in as Many Programming Languages as Possible","headline":"File Input Output in Elixir","mainEntityOfPage":{"@type":"WebPage","@id":"https://sampleprograms.io/projects/file-input-output/elixir/"},"url":"https://sampleprograms.io/projects/file-input-output/elixir/"}</script> |
| 43 | +<!-- End Jekyll SEO tag --> |
| 44 | + |
| 45 | + |
| 46 | + <meta name="theme-color" content="#157878"> |
| 47 | + <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"> |
| 48 | + <meta name="monetization" content="$ilp.uphold.com/qgNaxDa2QH77"> |
| 49 | + |
| 50 | + <!-- start custom head snippets, customize with your own _includes/head-custom.html file --> |
| 51 | + |
| 52 | +<!-- Setup Google Analytics --> |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | +<!-- You can set your favicon here --> |
| 57 | +<!-- link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" --> |
| 58 | + |
| 59 | +<!-- end custom head snippets --> |
| 60 | + |
| 61 | +</head> |
| 62 | + |
| 63 | +<!-- Default document body --> |
| 64 | +<body> |
| 65 | + <div class="wrapper"> |
| 66 | + <header class="page-header" role="banner"> |
| 67 | + <h1 class="header"> |
| 68 | + Sample Programs in Every Language |
| 69 | + </h1> |
| 70 | + |
| 71 | + <p class="header"> |
| 72 | + A Collection of Code Snippets in as Many Programming Languages as Possible |
| 73 | + </p> |
| 74 | + |
| 75 | + <ul> |
| 76 | + |
| 77 | + <li class="download"> |
| 78 | + <a class="buttons" href="https://github.com/TheRenegadeCoder/sample-programs-website/zipball/main">Download ZIP</a> |
| 79 | + </li> |
| 80 | + <li class="download"> |
| 81 | + <a class="buttons" href="https://github.com/TheRenegadeCoder/sample-programs-website/tarball/main">Download TAR</a> |
| 82 | + </li> |
| 83 | + |
| 84 | + |
| 85 | + <li> |
| 86 | + <a class="buttons github" href="https://github.com/TheRenegadeCoder/sample-programs-website"> |
| 87 | + View on GitHub |
| 88 | + </a> |
| 89 | + </li> |
| 90 | + </ul> |
| 91 | + |
| 92 | + |
| 93 | + <p class="header"> |
| 94 | + This project is maintained by |
| 95 | + <a class="header name" href="https://github.com/TheRenegadeCoder"> |
| 96 | + TheRenegadeCoder |
| 97 | + </a> |
| 98 | + </p> |
| 99 | + |
| 100 | +</header> |
| 101 | + |
| 102 | + <section> |
| 103 | + <nav class="top-nav"> |
| 104 | + <ul> |
| 105 | + <li><a href="/" id="home">Home</a></li> |
| 106 | + <li><a href="/languages/" id="lang">Languages</a></li> |
| 107 | + <li><a href="/projects/" id="proj">Projects</a></li> |
| 108 | + </ul> |
| 109 | +</nav> |
| 110 | + |
| 111 | + <nav aria-label="Breadcrumb" class="site-navigation"> |
| 112 | + <ol class="breadcrumb"> |
| 113 | + <li><a href="/">Home</a></li> |
| 114 | + |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | + <li> |
| 125 | + |
| 126 | + <a href="/projects/"> |
| 127 | + Projects |
| 128 | + </a> |
| 129 | + |
| 130 | + </li> |
| 131 | + |
| 132 | + |
| 133 | + |
| 134 | + |
| 135 | + |
| 136 | + <li> |
| 137 | + |
| 138 | + <a href="/projects/file-input-output/"> |
| 139 | + File input output |
| 140 | + </a> |
| 141 | + |
| 142 | + </li> |
| 143 | + |
| 144 | + |
| 145 | + |
| 146 | + |
| 147 | + |
| 148 | + <li> |
| 149 | + |
| 150 | + <span class="active"> |
| 151 | + Elixir |
| 152 | + </span> |
| 153 | + |
| 154 | + </li> |
| 155 | + |
| 156 | + </ol> |
| 157 | +</nav> |
| 158 | + |
| 159 | + <h1>File Input Output in Elixir</h1> |
| 160 | + |
| 161 | + |
| 162 | + <small> |
| 163 | + |
| 164 | + Published on 28 May 2026 |
| 165 | + |
| 166 | + |
| 167 | + |
| 168 | + (Updated: 28 May 2026) |
| 169 | + |
| 170 | + </small> |
| 171 | + |
| 172 | + |
| 173 | + |
| 174 | + |
| 175 | +<div class="featured-image"> |
| 176 | + <img |
| 177 | + src="/assets/images/file-input-output-in-every-language.jpg" |
| 178 | + alt="File Input Output in Elixir" |
| 179 | + loading="eager" |
| 180 | + > |
| 181 | + |
| 182 | + |
| 183 | + <div class="image-container" id="title1"> |
| 184 | + <div class="image-title">File Input</div> |
| 185 | + </div> |
| 186 | + |
| 187 | + |
| 188 | + |
| 189 | + <div class="image-container" id="title2"> |
| 190 | + <div class="image-title">Output in Elixir</div> |
| 191 | + </div> |
| 192 | + |
| 193 | +</div> |
| 194 | + |
| 195 | +<p></p> |
| 196 | + |
| 197 | + |
| 198 | + <!-- |
| 199 | +AUTO-GENERATED -- PLEASE DO NOT EDIT! |
| 200 | +
|
| 201 | +Instead, please edit the following: |
| 202 | +
|
| 203 | +- sources/programs/file-input-output/elixir/how-to-implement-the-solution.md |
| 204 | +- sources/programs/file-input-output/elixir/how-to-run-the-solution.md |
| 205 | +
|
| 206 | +See .github/CONTRIBUTING.md for further details. |
| 207 | +--> |
| 208 | + |
| 209 | +<p>Welcome to the <a href="/projects/file-input-output">File Input Output</a> in <a href="/languages/elixir">Elixir</a> page! Here, you'll find the source code for this program as well as a description of how the program works.</p> |
| 210 | + |
| 211 | +<h2 id="current-solution">Current Solution</h2> |
| 212 | + |
| 213 | +<div class="language-elixir highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">with</span> <span class="ss">:ok</span> <span class="o"><-</span> <span class="no">File</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"output.txt"</span><span class="p">,</span> <span class="s2">"Oh, hi Mark."</span><span class="p">),</span> |
| 214 | + <span class="p">{</span><span class="ss">:ok</span><span class="p">,</span> <span class="n">contents</span><span class="p">}</span> <span class="o"><-</span> <span class="no">File</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="s2">"output.txt"</span><span class="p">)</span> <span class="k">do</span> |
| 215 | + <span class="no">String</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="n">contents</span><span class="p">,</span> <span class="s2">"</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span> <span class="o">|></span> <span class="no">Enum</span><span class="o">.</span><span class="n">each</span><span class="p">(</span><span class="o">&</span><span class="no">IO</span><span class="o">.</span><span class="n">puts</span><span class="o">/</span><span class="mi">1</span><span class="p">)</span> |
| 216 | +<span class="k">else</span> |
| 217 | + <span class="p">{</span><span class="ss">:error</span><span class="p">,</span> <span class="n">reason</span><span class="p">}</span> <span class="o">-></span> <span class="ss">:file</span><span class="o">.</span><span class="n">format_error</span><span class="p">(</span><span class="n">reason</span><span class="p">)</span> |
| 218 | +<span class="k">end</span> |
| 219 | + |
| 220 | +</code></pre></div></div> |
| 221 | + |
| 222 | +<p>File Input Output in <a href="/languages/elixir">Elixir</a> was written by:</p> |
| 223 | + |
| 224 | +<ul> |
| 225 | + <li>Ricardo Mapurunga Junior</li> |
| 226 | +</ul> |
| 227 | + |
| 228 | +<p>If you see anything you'd like to change or update, <a href="https://github.com/TheRenegadeCoder/sample-programs">please consider contributing</a>.</p> |
| 229 | + |
| 230 | +<h2 id="how-to-implement-the-solution">How to Implement the Solution</h2> |
| 231 | + |
| 232 | +<p>No 'How to Implement the Solution' section available. <a href="https://github.com/TheRenegadeCoder/sample-programs-website">Please consider contributing</a>.</p> |
| 233 | + |
| 234 | +<h2 id="how-to-run-the-solution">How to Run the Solution</h2> |
| 235 | + |
| 236 | +<p>No 'How to Run the Solution' section available. <a href="https://github.com/TheRenegadeCoder/sample-programs-website">Please consider contributing</a>.</p> |
| 237 | + |
| 238 | +</section> |
| 239 | + |
| 240 | + <footer class="site-footer" role="contentinfo"> |
| 241 | + |
| 242 | + <span class="site-footer-owner"> |
| 243 | + <a href="https://github.com/TheRenegadeCoder/sample-programs-website"> |
| 244 | + sample-programs-website |
| 245 | + </a> |
| 246 | + is maintained by |
| 247 | + <a href="https://github.com/TheRenegadeCoder">TheRenegadeCoder</a>. |
| 248 | + </span> |
| 249 | + |
| 250 | +</footer> |
| 251 | + |
| 252 | + </div> |
| 253 | +</body> |
| 254 | +<!-- End of default document body --> |
| 255 | + |
| 256 | +</html> |
0 commit comments