public class Test2 { public static void main(String[] args) throws IOException { InputStream resourceAsStream = Test2.class.getResourceAsStream("/image/image_1.png"); FileOutputStream fileOutputStream = new FileOutputStream("D://test.png"); BufferedInputStream bufferedInputStream = new BufferedInputStream(resourceAsStream); BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream); byte[] bytes = new byte[1024]; while (bufferedInputStream.read(bytes) != -1){ bufferedOutputStream.write(bytes); } bufferedOutputStream.flush(); bufferedOutputStream.close(); bufferedInputStream.close(); } }