Here you can find the source of toFile(Class c, String resource)
Parameter | Description |
---|---|
c | class to be used to find the resource |
resource | name of the desired resource |
Parameter | Description |
---|---|
IllegalArgumentException | if the URL of the specified resource does not adhere to the<code>file</code> scheme |
public static File toFile(Class c, String resource)
//package com.java2s; /*//from ww w. j ava2 s. c o m * JBoss, Home of Professional Open Source * Copyright 2005, JBoss Inc., and individual contributors as indicated * by the @authors tag. * * This is free software; you can redistribute it and/or modify it * under the terms of the JBPM BPEL PUBLIC LICENSE AGREEMENT as * published by JBoss Inc.; either version 1.0 of the License, or * (at your option) any later version. * * This software 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. */ import java.io.File; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; public class Main { /** * Converts the URL of the specified resource into an abstract pathname. * @param c class to be used to find the resource * @param resource name of the desired resource * @return the abstract pathname denoted by the specified resource * @throws IllegalArgumentException if the URL of the specified resource does not adhere to the * <code>file</code> scheme */ public static File toFile(Class c, String resource) { URL resourceUrl = c.getResource(resource); if (resourceUrl == null) return null; try { return new File(new URI(resourceUrl.toExternalForm())); } catch (URISyntaxException e) { // should not happen throw new AssertionError(e); } } }