Here you can find the source of copyResource(String name)
private static File copyResource(String name) throws Exception
//package com.java2s; //License from project: Apache License import com.google.common.io.ByteStreams; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.net.URLClassLoader; public class Main { private static File copyResource(String name) throws Exception { InputStream is = URLClassLoader.getSystemResourceAsStream(name); String tempDir = System.getProperty("java.io.tmpdir"); File tmp = new File(tempDir + File.separator + name); tmp.deleteOnExit();/*www .ja v a2 s. c o m*/ ByteStreams.copy(is, new FileOutputStream(tmp)); return tmp; } }