File path compare

In this chapter you will learn:

  1. How to compare two file path

Compare two file path

The following methods compare the file paths not the file content.

  • int compareTo(File pathname)
    compares two file lexicographically.
  • boolean equals(Object obj)
    tests this abstract pathname for equality with the given object.
import java.io.File;
//from   j a  v a  2s .  com
public class Main {

  public static void main(String[] args) {

    File aFile = new File("c:/aFolder");
    File bFile = new File("c:/bFolder");
    
    System.out.println(aFile.equals(bFile));//false

  }
}

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. How to delete a file in Java
  2. How to delete a file on exiting the JVM
Home » Java Tutorial » File
File
File across Operating System
File properties
File creation
File path
File path compare
File delete
File parent folder
File drive root
File size/length
File new directories
File rename
File modified time
File executable, readable or writable
File location to URI
File copy