Here you can find the source of getUri(File file)
Parameter | Description |
---|---|
file | The input file. |
Parameter | Description |
---|---|
MalformedURLException | if an error occur while constructing the URI for the givenfile. |
public static String getUri(File file) throws MalformedURLException
//package com.java2s; // are made available under the terms of the Eclipse Public License v1.0 import java.io.File; import java.net.MalformedURLException; public class Main { /**/*w ww . j av a 2 s . co m*/ * Returns the URI for the given file. * * @param file * The input file. * @return The URI for the given file. * @throws MalformedURLException * if an error occur while constructing the URI for the given * file. */ public static String getUri(File file) throws MalformedURLException { String url = file.toURL().toExternalForm(); StringBuffer strBuf = new StringBuffer(); int urlLength = url.length(); for (int i = 0; i < urlLength; i++) { char ch = url.charAt(i); switch (ch) { case ' ': strBuf.append("%20"); //$NON-NLS-1$ break; default: strBuf.append(ch); break; } } return strBuf.toString(); } }