title: Java: Copying a File (using Path) to a directory and renaming a file with the same name
body: <p>I'm new to Java and working on a project to improve my skills and need some help.</p>
  
  <p>I have a file, lets call it <code>tools.extension</code>, it is going to have to go to a directory that already has a <code>tools.extension</code> file. I want my code to check that <code>tools.extension</code> exists, and if it does, to rename it to <code>tools(currentdate).extension</code>.</p>
  
  <p>So I tried this to test the logic:</p>
  
  <pre><code>Scanner myS = new Scanner(System.in);
          Path path = Paths.get(myS.nextLine());
          Path file = Files.createFile(path);
          Path path1 = Paths.get(myS.nextLine());
          Path file1 = Files.createFile(path1);
  
         if (file.getFileName() == file1.getFileName())
  
         {
             System.out.println("file already exists");
         }
  
         else
         {
             System.out.println("File doesn't already exist");
         }
  
         Files.delete(file);
         Files.delete(file1);
  </code></pre>
  
  <p>But of course then I realized that there is going to be an exception somewhere, but I just wanted to try this to check my logic.</p>
  
  <p>And I always get <code>file doesn't already exist</code></p>
  
  <p>not even if I create two <code>text.txt</code> files in different directories. It doesn't see them as having the same name, even though when I print <code>getFileName()</code>, both of them are!</p>
  
  <p>Could someone give me some advice or point me towards a tutorial that'll help me?</p>
  
  <p>Thank you ever so much!</p>
  
  <p>EDIT:</p>
  
  <p>Thank so much for reminding me of the .equals, it is working!</p>
  
  <p>I just have another question, how do I go about renaming file or file1? Them being paths I don't know of a way.</p>
  
  <p>Should I use a toFile() method and then use renameTo()?</p>