title: java.io.FileNotFoundException: hi.txt (The system cannot find the file specified) at java.base/java.io.FileOutputStream.open0(Native Method)
body: <p>So basically I am stuck compiling this simple code that creates a new .txt file and write something into it. Don't know how to deal with this <strong>The system cannot find the file specified</strong> issue.</p>
  <p>Here is my code :</p>
  <pre class="lang-java prettyprint-override"><code>import java.io.File;
  import java.io.FileWriter;
  
  public class CreateANewFile {
  
      public static void main(String[] args) {
          File file = new File(&quot;hi.txt&quot;);
          if (!file.isFile()) {
              try {
                  file.createNewFile();
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
          FileWriter writer;
          try {
              writer = new FileWriter(file);
              writer.write(&quot;null&quot;);
              writer.close();
              System.out.println(&quot;done!! check if the file has created or not.&quot;);
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  <p>This is error:</p>
  <pre><code>   java.io.IOException: The system cannot find the file specified
          at java.base/java.io.WinNTFileSystem.createFileExclusively(Native Method)
          at java.base/java.io.File.createNewFile(File.java:1024)
          at CreateANewFile.main(CreateANewFile.java:10)
  java.io.FileNotFoundException: hi.txt (The system cannot find the file specified)
          at java.base/java.io.FileOutputStream.open0(Native Method)
          at java.base/java.io.FileOutputStream.open(FileOutputStream.java:292)
          at java.base/java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:235)
          at java.base/java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:185)
          at java.base/java.io.FileWriter.&lt;init&gt;(FileWriter.java:96)
          at CreateANewFile.main(CreateANewFile.java:17)
  </code></pre>
  <p>So basically, JVM is not being allowed to create or write into any file.</p>
  <p>I have cross checked that all of my environment variables are having correct path.</p>
  <p>What is going wrong ??
  How to solve the issue ?</p>
  <p>Thanks in Advance. :)</p>