Package test

Source Code of test.PathTest

package test;

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

public class PathTest {

  /**
   * @param args
   * @throws IOException
   */
  public static void main(String[] args) throws IOException {
   
    Path filePath = Paths.get(".//file.txt");

    System.out.println(filePath.getFileName());
    System.out.println(filePath.getParent());
    System.out.println(filePath.getRoot());
    System.out.println(filePath.isAbsolute());
   
    Path normalizedPath = filePath.normalize();
    System.out.println(normalizedPath);
   
    System.out.println(filePath.toUri());
    System.out.println(normalizedPath.toUri());
   
    System.out.println(filePath.toAbsolutePath());
    System.out.println(filePath.toAbsolutePath().normalize());

    System.out.println(filePath.toRealPath());

    Path nonExistingFilePath = Paths.get(".//lob//file.txt");
    System.out.println(nonExistingFilePath.toAbsolutePath());
   
    // Should exists on the filesystem!! Throws IOException !!!
//    nonExistingFilePath.toRealPath();
   
    System.out.println(nonExistingFilePath.compareTo(normalizedPath));
  }

}
TOP

Related Classes of test.PathTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.