Java Utililty Methods URI to File Name

List of utility methods to do URI to File Name

Description

The list of methods to do URI to File Name are organized into topic(s).

Method

java.io.FilegetFile(java.net.URI uri)
get File
if (uri != null) {
    if (uri.getScheme().equalsIgnoreCase("file")) {
        return new java.io.File(uri);
    } else {
        return null;
} else {
    return null;
...
FilegetFile(String ontURI)
Creates a file object for the given local ontology file URI.
return new File(new URI(ontURI));
StringgetFile(String uri)
Loads a file from a URI, downloading it.
String txt = "";
try {
    URL oracle = new URL(uri);
    BufferedReader in = new BufferedReader(new InputStreamReader(oracle.openStream()));
    String inputLine;
    while ((inputLine = in.readLine()) != null) {
        txt += inputLine + " \n";
    in.close();
} catch (Exception e) {
return txt;
FilegetFile(URI uri)
get File
if (uri == null)
    return null;
String proto = uri.toURL().getProtocol();
if (proto == null) {
    return new File(uri);
} else if ("file".equalsIgnoreCase(proto)) 
    String path = uri.toString().replace("file:", "");
...
FilegetFile(URI uri)
Resolves the specified URI, and returns the file represented by the URI.
if (uri == null)
    throw new IllegalArgumentException("The URI cannot be null.");
if (!"file".equals(uri.getScheme()))
    throw new IllegalArgumentException("Wrong URI scheme for path resolution, expected \"file\" "
            + "and got \"" + uri.getScheme() + "\"");
if (uri.getAuthority() != null)
    try {
        uri = new URI(uri.toString().replace("file://", "file:/"));
...
FilegetFile(URI uri)
Constructs a File instance from a file URI.
assert uri != null;
File result;
final String scheme = uri.getScheme();
if ((scheme == null) || !scheme.toLowerCase(Locale.ROOT).equals("file")) { 
    result = null;
} else {
    try {
        result = new File(uri);
...
FilegetFileByPathOrURI(String path)
get File By Path Or URI
path = path.trim();
if (path.startsWith("file://")) {
    path = path.replace(" ", "%20");
    return new File(new URI(path));
} else {
    return new File(path);
StringgetFileFromURIList(URI[] uris, String fileName)
get File From URI List
for (URI uri : uris) {
    if (uri.getPath().endsWith(fileName)) {
        return uri.getPath();
return null;
StringgetFilename(final URI uri)
Returns the filename for the specified URI.
if (uri == null)
    throw new IllegalArgumentException("The URI cannot be null.");
final String path = uri.getRawPath();
final int finalSeparator = Math.max(path.lastIndexOf('/'), path.lastIndexOf('\\'));
if (finalSeparator == -1)
    throw new IllegalArgumentException("A separator character could not found in the specified URI.");
if (finalSeparator == path.length() - 1)
    throw new IllegalArgumentException("The specified URI does not point to a file resource.");
...
StringgetFilename(final URI uri)
Gets the file name of a given URI
URL url;
if (uri == null) {
    throw new MalformedURLException("The input URL 'null' is not valid");
url = uri.toURL();
String filePath = url.getFile();
int lastIndex = filePath.lastIndexOf(URL_SEPARATOR);
String filenameWithParameters = filePath.substring(lastIndex + 1);
...