Here you can find the source of getResourceAsFile(Class> clazz, String fn)
public static File getResourceAsFile(Class<?> clazz, String fn) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.IOException; import java.net.URL; public class Main { /** Get a file to read the raw contents of the given resource :) */ public static File getResourceAsFile(Class<?> clazz, String fn) throws IOException { URL url = clazz.getResource(fn); if (url == null || url.getFile() == null) { throw new IOException("resource \"" + fn + "\" relative to " + clazz + " not found."); }// w ww.j a v a 2 s. co m return new File(url.getFile()); } }