Here you can find the source of getFile(URL url)
Parameter | Description |
---|---|
url | the URL to resolve to File |
public static File getFile(URL url)
//package com.java2s; /*/*from ww w .j a v a 2 s . c o m*/ Copyright 2012 Andrius Velykis This file is part of the CZT project. The CZT project is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. The CZT project is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with CZT. If not, see <http://www.gnu.org/licenses/>. */ import java.io.File; import java.net.URL; public class Main { /** * Resolves a {@link File} from {@link URL}. Checks if the protocol is `file:`, otherwise returns * {@code null}. * * @param url the URL to resolve to File * @return File represented by the URL, or {@code null} if the URL is not file-based. */ public static File getFile(URL url) { if (url == null) { return null; } if ("file".equals(url.getProtocol())) { return new File(url.getFile()); } // for non-files, just return null return null; } }