title: File I/O, Creation of Path with Constructor Variable
body: <p>How to create a path &amp; file using the constructor variables</p>
  
  <p>I am writing a simple logging application for my school. When I initialize the name variable for the logging the application works without a problem.</p>
  
  <p>However, when I create an instance with a different name given in the constructor, the program goes to the instance variable to create a null logging file before creating the new logging file. </p>
  
  <p>Also when I rerun the application it always gives an exception the file has already been found, but as far as I can see this should be resolved in a loop in my code. </p>
  
  <p>I feel I am missing something about Path mechanics or something else but I can't figure it out. </p>
  
  <pre><code>private String name;
  private int logLevel;
  private Path path = checkPreviousVersions();
  
  
  protected FlexibleLogger(String name,int logLevel) throws IOException {
      this.logLevel = logLevel;
      this.name=name;
          }
  
  public Path checkPreviousVersions() throws IOException{
  
      List&lt;String&gt; results = new ArrayList&lt;&gt;();
      List&lt;String&gt; fresults = new ArrayList&lt;&gt;();
      File[] files = new File("./logs").listFiles();
  
      for (File file: files) {
          if (file.isFile()) {
              results.add(file.getName());
          }
      }
  
      for (String result: results){
          fresults.add(result.replace(result,result.substring(0,result.indexOf("."))));
      }
  
      if (fresults.contains(name)) {
          Path mypath = Paths.get("./logs/" + name + ".log");
          String s = "=======================" + dateFormatter() + "=======================" + "\n";
          writeToFile(s);
          return mypath;
  
  
      } else {
          Path mypath = Paths.get("./logs/" + name + ".log");
          Files.createFile(mypath);
          return mypath;
  
      }
  
  }
  </code></pre>
  
  <p>The expected result is one file for the first creation and a new file every time the name is changed. If the name is not changed it should update the existing file.</p>
  
  <p>The actual result is the creation of two files, one "null" and one with the constructor name variable. On a second loop with the same name, it gives "FileAlreadyExists" error.</p>
  
  <p>Thank you kindly for any advice.</p>