title: Where do I need to put file to be read by Rust?
body: <p>When I was reading through the tutorial for Rust here (<a href="https://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.html" rel="noreferrer">https://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.html</a>). I found this block of code:</p>
  <pre><code>use std::fs::File;
  
  fn main() {
     let f = File::open(&quot;hello.txt&quot;);
  
     let f = match f {
        Ok(file) =&gt; file,
        Err(error) =&gt; panic!(&quot;Problem opening the file: {:?}&quot;, error),
     };
  }
  </code></pre>
  <p>It always displays an error: <code>{ code: 2, kind: NotFound, message: &quot;The system cannot find the file specified.&quot; }</code> even when I make a <code>hello.txt</code> at the root folder of the <code>src</code>, it fails to read it.</p>
  <p>In <a href="https://doc.rust-lang.org/rust-by-example/std_misc/file/open.html" rel="noreferrer">another example here</a>, I use <code>cargo run</code> to no success. The program still fails to read <code>hello.txt</code> file. I'm aware that the example uses <code>rustc open.rs &amp;&amp; ./open</code>. Since I don't understand why is it suddenly use different compile method and what's it even mean... I just kinda skip it and try to use <code>cargo run</code> instead</p>
  <p>Where do I need to put my file here so <code>cargo run</code> can read it ?</p>
  <p>Also if I run the production code and need the program to read an external file, where do I need to put it ?</p>
  <p>Here's my folder structure. Pretty simple since I just start to learn RUST.
  Thank you in advance.</p>
  <p><a href="https://i.stack.imgur.com/tvCHG.png" rel="noreferrer"><img src="https://i.stack.imgur.com/tvCHG.png" alt="folder structure" /></a></p>