title: Returning to the main method in java
body: <p>How to return to the main method and execute again the whole program? I tried the return but it just ends the execution.</p>
  
  <p>This is the code:</p>
  
  <pre><code>    File folder = new File("C:\my path");
      File[] listOfFiles = folder.listFiles();
  
          if (folder.isDirectory()){
              if(folder.list().length&gt;0){
                  System.out.println("Directory is not empty!");
  
              }
              else {
                  System.out.println("Directory is empty!");
                  return; //I need to return from the main method
              }
          }
          else{
              System.out.println("Invalid directory!");
          }
  </code></pre>
  
  <p>I want to return to the main method if the directory is empty. I used the return but, it did not return from the start :( Any idea on how to return to the main method? Thanks :)</p>
  
  <p>This is the entire main method: (Sorry if it is too long)
  <a href="https://i.stack.imgur.com/00vM8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/00vM8.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/Su7bT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Su7bT.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/0pJRr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0pJRr.png" alt="enter image description here"></a></p>
  
  <p>My goal is to check if a new file entered the directory. Then it will list the files on that directory and one-by-one it will be deleted. If there's no file from the directory, it will return to the start.</p>
  
  <p><strong>Comment correction:</strong> "//It will return to the start"</p>
  
  <p><strong>The two loops:</strong> The second loop will be executed during the execution of the first loop. (Sorry if I did not indent it). After the execution of the second loop, it will return to the first loop. <a href="https://i.stack.imgur.com/AL76U.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AL76U.png" alt="enter image description here"></a></p>