File location to URI

In this chapter you will learn:

  1. Convert file location to URI and URL

Convert file location to URI and URL

URI toURI() creates a file: URI that represents this abstract pathname.

import java.io.File;
/*from  j  av a2s.com*/
public class Main {

  public static void main(String[] args) {
    File file = new File("c:/a.htm");
    System.out.println(file.toURI());
  }
}

The output:

file:/c:/a.htm

Next chapter...

What you will learn in the next chapter:

  1. How to use FileInputStream and FileOutputStream to copy a file