Here you can find the source of getFileFromClassLoader(String fileName)
Parameter | Description |
---|---|
clazz | Class. |
fileName | Name of file. |
null
if none.
public static File getFileFromClassLoader(String fileName)
//package com.java2s; //LICENCE-START/*from w w w. j ava2 s . c om*/ import java.io.File; import java.net.URL; public class Main { /** * Helper method which gets a file using the current class loader. * * @param clazz * Class. * @param fileName * Name of file. * @return file object or <code>null</code> if none. */ public static File getFileFromClassLoader(String fileName) { URL url = Thread.currentThread().getContextClassLoader().getResource(fileName); File file = null; if (url != null) { file = new File(url.getFile()); } return file; } }