Java URI from toUri(String path)

Here you can find the source of toUri(String path)

Description

to Uri

License

Open Source License

Declaration

public static URI toUri(String path) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

import java.net.URI;
import java.net.URISyntaxException;

public class Main {
    public static URI toUri(String path) {
        if (path == null || path.isEmpty()) {
            return null;
        }/*from  ww  w  .jav  a2 s  . co  m*/

        File file = new File(path);
        if (file.exists()) {
            path = file.getAbsolutePath();
        }
        URI uri;
        try {
            uri = new URI(path.replace('\\', '/'));
        } catch (URISyntaxException e) {
            throw new RuntimeException(e);
        }
        return uri.normalize();
    }
}

Related

  1. toURI(String location)
  2. toURI(String location)
  3. toURI(String location)
  4. toURI(String location)
  5. toURI(String path)
  6. toURI(String s)
  7. toURI(String str)
  8. toURI(String str)
  9. toURI(String sUri)