Here you can find the source of getResourceAsFile(Class> clazz, String rscName)
public static File getResourceAsFile(Class<?> clazz, String rscName)
//package com.java2s; //License from project: Apache License import java.io.File; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; public class Main { public static File getResourceAsFile(Class<?> clazz, String rscName) { File file = null;/*ww w. j a v a2 s.co m*/ try { final URL url = clazz.getClassLoader().getResource(rscName); if (url != null) file = new File(new URI(url.toString())); } catch (URISyntaxException e) { e.printStackTrace(); } return file; } }