Java URL to File Name getFileFromURL(URL urlToDecode)

Here you can find the source of getFileFromURL(URL urlToDecode)

Description

Work-around for a bug/faulty design in getResource().getFile(), making space %20 etc

License

BSD License

Declaration

public static File getFileFromURL(URL urlToDecode) 

Method Source Code

//package com.java2s;
/***/*  w  w w . ja v  a  2 s .c  o m*/
 * Copyright (C) 2010 Johan Henriksson
 * This code is under the Endrov / BSD license. See www.endrov.net
 * for the full text and how to cite.
 */

import java.io.File;

import java.io.UnsupportedEncodingException;
import java.net.*;

public class Main {
    /**
     * Work-around for a bug/faulty design in getResource().getFile(), making space %20 etc
     */
    public static File getFileFromURL(URL urlToDecode) {
        try {
            return new File(URLDecoder.decode(urlToDecode.getFile(),
                    "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return null;
        }
    }
}

Related

  1. getFileFromUrl(String url, File base)
  2. getFileFromUrl(String urlPath)
  3. getFileFromURL(URL url)
  4. getFileFromURL(URL url)
  5. getFileFromUrl(URL url)
  6. getFileName(final CharSequence url)
  7. getFileName(final URL url)
  8. getFilename(final URL url)
  9. getFilename(final URL url, int maxLength)