Here you can find the source of getResourceFile(String sResourcePath, Class> cRefClass)
Parameter | Description |
---|---|
sResourcePath | Path relative to the given class. |
cRefClass | Reference class. |
null
if the file was not found.
public static File getResourceFile(String sResourcePath, Class<?> cRefClass)
//package com.java2s; //License from project: Apache License import java.io.File; import java.net.URL; public class Main { /**/*from w ww.j av a 2s. c o m*/ * Returns the given resource as a file. This method does not work for classes packaged in a jar * file. * * @param sResourcePath Path relative to the given class. * @param cRefClass Reference class. * * @return File object pointing to the given file or <code>null</code> if the file was not * found. */ public static File getResourceFile(String sResourcePath, Class<?> cRefClass) { URL url = cRefClass.getResource(sResourcePath); if (url == null) { return null; } String filePath = url.getFile(); if (filePath == null) { return null; } // Replace %20 in the URL with spaces. filePath = filePath.replaceAll("%20", " "); return new File(filePath); } }