Partial Path comparison can be accomplished by using the startsWith() and endsWith() methods - Java File Path IO

Java examples for File Path IO:Path

Description

Partial Path comparison can be accomplished by using the startsWith() and endsWith() methods

Demo Code

import java.nio.file.Path;
import java.nio.file.Paths;

public class Main {
  public static void main(String[] args) {
    Path path01 = Paths.get("/folder1/folder2/folder3/test.txt");

    boolean sw = path01.startsWith("/folder1/folder2");  
    boolean ew = path01.endsWith("test.txt");  
    System.out.println(sw);  /*from  w  w w  . j  a  v a 2s .  c  om*/
    System.out.println(ew); 


  }
}

Result


Related Tutorials