Here you can find the source of getFileByPathOrURI(String path)
public static File getFileByPathOrURI(String path) throws URISyntaxException
//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); } } }