Java URL to File Name getFileFromURL(URL url)

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

Description

get File From URL

License

Apache License

Declaration

public static File getFileFromURL(URL url) 

Method Source Code

//package com.java2s;
/**//from   w w  w .j av a  2  s .  c om
 * Copyright ?? 2010-2014 Nokia
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.File;

import java.net.URISyntaxException;
import java.net.URL;

public class Main {
    public static File getFileFromURL(URL url) {
        try {
            return new File(url.toURI());
        } catch (URISyntaxException e) {
            throw new IllegalArgumentException(String.format("URL contains an invalid URI syntax: %s", url), e);
        }
    }
}

Related

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