Java Path Convert To filePathToUrl(String filePath)

Here you can find the source of filePathToUrl(String filePath)

Description

Transforms an absolute file path in the local file system into a URL-compatible address for the file.

License

Apache License

Parameter

Parameter Description
filePath the absolute path to the file, including drive (i.e., "C:\Program Files...")

Return

a URL address for the local file

Declaration

public static String filePathToUrl(String filePath) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//w  ww.  j a  v a2 s .co m
     * Transforms an absolute file path in the local file system into
     * a URL-compatible address for the file.
     * 
     * @param filePath  the absolute path to the file, including drive (i.e., "C:\Program Files...")
     * @return          a URL address for the local file
     */
    public static String filePathToUrl(String filePath) {
        if (filePath.startsWith("/")) {
            return "file://" + filePath;
        } else {
            return "file:///" + filePath;
        }
    }
}

Related

  1. filePathToClassNameOrNull(String filePathWithExtension)
  2. filePathToClassPath(String path)
  3. filePathToJavaBinaryName(final String filePath, final String separator)
  4. filePathToPackagePathOrNull(String path)
  5. pathTo(String filename)
  6. pathTo(String ref)
  7. pathToAdjacencyList(final int[] path, final int[] adjacencyList)
  8. pathToClassName(String path)