Java URL to convertURLToFile(URL url)

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

Description

convert URL To File

License

Open Source License

Declaration

public static File convertURLToFile(URL url) 

Method Source Code

//package com.java2s;
/*/*ww  w  .ja v  a  2  s.  c  o  m*/
 * Copyright 2011-2016 ZXC.com All right reserved. This software is the confidential and proprietary information of
 * ZXC.com ("Confidential Information"). You shall not disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into with ZXC.com.
 */

import java.io.File;

import java.io.UnsupportedEncodingException;

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

public class Main {
    public static File convertURLToFile(URL url) {
        if (url == null) {
            return null;
        }

        try {
            return new File(url.toURI());
        } catch (URISyntaxException e) {
            try {
                return new File(URLDecoder.decode(url.getPath(), "UTF-8"));
            } catch (UnsupportedEncodingException e1) {
                return new File(url.getPath());
            }
        }
    }
}

Related

  1. convertURIToURL(URI uri)
  2. convertURL(String url)
  3. convertUrlToFilename(URL url)
  4. convertUrlToFilePath(URL url)
  5. convertUrlToHostNameAsNodeName(String url)
  6. convertUrlToMp3Cmd(final String url)