Interoperability between java.io.File and java.nio.file.Files - Java File Path IO

Java examples for File Path IO:File Operation

Description

Interoperability between java.io.File and java.nio.file.Files

Demo Code

import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Main {

  public static void main(String[] args) {
    try {/*  w ww  .  j  av a2 s  .c om*/
      Path path = Paths.get(new URI("file:///C:/home/docs/users.txt"));
      File file = new File("C:\\home\\docs\\users.txt");
      Path toPath = file.toPath();
      System.out.println(toPath.equals(path));
    } catch (URISyntaxException e) {
      System.out.println("Bad URI");
    }
  }
}

Related Tutorials