Here you can find the source of getFileFromClasspath(final String fileName)
Parameter | Description |
---|---|
fileName | a parameter |
public static File getFileFromClasspath(final String fileName)
//package com.java2s; //License from project: Apache License import java.io.File; import java.net.URL; public class Main { /**// ww w .j a v a 2 s . c o m * Load the resource either using current class loader or using parent class * loader * * @param fileName * @return */ public static File getFileFromClasspath(final String fileName) { File file = null; // Load the resource using current class loader URL url = Thread.currentThread().getClass().getResource(fileName); if (url != null) { file = new File(url.getFile()); } else { // load the resource using the parent context url = Thread.currentThread().getContextClassLoader().getResource(fileName); if (url != null) { file = new File(url.getFile()); } } return file; } }