title: How do I read a local file in Deno?
body: <p>I'm writing a word count program written in TypeScript that I'm trying to run in Deno. I'm invoking it with no arguments, just <code>deno ./word_count.ts</code>, so it should have the default read-only filesystem access. I was hoping that I might be able to use <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch" rel="noreferrer">the standard browser <code>fetch()</code> API</a> with <a href="https://en.wikipedia.org/wiki/File_URI_scheme" rel="noreferrer">the <code>file:</code> URL scheme</a> to read from the filesystem, like this:</p>
  
  &nbsp; <strong><code>word_count.ts</code></strong>
  
  <pre class="lang-js prettyprint-override"><code>const countWords = (s: string): number =&gt;
  s.split(/\s+/g).filter(w =&gt; /[a-z0-9]/.test(w)).length;
  
  const main = async () =&gt; {
      const text = await (await fetch("file:///./input.txt")).text();
      const count = countWords(text);
      console.log(`I read ${count} words.`);
  };
  
  main();
  </code></pre>
  
  &nbsp; <strong><code>input.txt</code></strong>
  
  <pre class="lang-none prettyprint-override"><code>The quick brown fox jumps over the lazy dog.
  </code></pre>
  
  <p>But when I try I see I see that <code>fetch</code> doesn't support <code>file</code> URLs:</p>
  
  <pre><code>Error: an error occurred trying to connect: invalid URL, scheme must be http
      at FetchResponse.onMsg (deno/js/fetch.ts:121:21)
      at FetchRequest.onMsg (deno/js/fetch.ts:152:19)
      at onFetchRes (deno/js/fetch.ts:28:8)
      at onMessage$1 (deno/js/main.ts:30:7)
  </code></pre>
  
  <hr>
  
  <p>How can I read the contents of a local file in Deno?</p>