Java URI to File Name getFileByPathOrURI(String path)

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

Description

get File By Path Or URI

License

Open Source License

Declaration

public static File getFileByPathOrURI(String path) throws URISyntaxException 

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 File getFileByPathOrURI(String path) throws URISyntaxException {
        path = path.trim();//from w ww.ja v a 2 s  .c om
        if (path.startsWith("file://")) {
            // drag and drop file to Swing text field, the uri may be invalid
            path = path.replace(" ", "%20");
            return new File(new URI(path));
        } else {
            return new File(path);
        }
    }
}

Related

  1. getFile(String ontURI)
  2. getFile(String uri)
  3. getFile(URI uri)
  4. getFile(URI uri)
  5. getFile(URI uri)
  6. getFileFromURIList(URI[] uris, String fileName)
  7. getFilename(final URI uri)
  8. getFilename(final URI uri)
  9. getFileName(URI path)