Say I have a file called test.txt in the package "com.test.io" in my bank.
How can I write a class that extracts this text file and then copies the contents to a new file in the file system?
Assuming the specified jar is in your classpath:
URL url = getClassLoader().getResource("com/test/io/test.txt"); FileOutputStream output = new FileOutputStream("test.txt"); InputStream input = url.openStream(); byte [] buffer = new byte[4096]; int bytesRead = input.read(buffer); while (bytesRead != -1) { output.write(buffer, 0, bytesRead); bytesRead = input.read(buffer); } output.close(); input.close();