Here you can find the source of getResourceAsFile(Class klass, String resource)
Parameter | Description |
---|---|
klass | a parameter |
resource | resource name relative to class |
public static File getResourceAsFile(Class klass, String resource)
//package com.java2s; /*//from w ww. j a va 2 s.co m * * * Copyright (C) 2007 Pingtel Corp., certain elements licensed under a Contributor Agreement. * Contributors retain copyright to elements licensed under a Contributor Agreement. * Licensed to the User under the LGPL license. * * $ */ import java.io.File; import java.net.URL; public class Main { /** * Retrieves the file corresponding to the class resource * * @param klass * @param resource resource name relative to class * @return file that can be opened and used to read resource */ public static File getResourceAsFile(Class klass, String resource) { URL url = klass.getResource(resource); return new File(url.getFile()); } }