|
Reading a binary file from JAR |
|
|
|
|
Tuesday, 10 July 2007 |
|
When you want to read a binary file from JAR file (read only), you can use following code in Java me. The binary file can be for example a game level, a map, or an arabic language script. You should include that file in your project, Jbuilder also requires to include that file in your wizard created JAR file and you have to run your project always from created jad/jar from within IDE or outside from folder on disk.
private byte[] readBinaryFile(String fileName) throws IOException { InputStream input = getClass().getResourceAsStream(fileName); ByteArrayOutputStream output = new ByteArrayOutputStream(1024); byte[] buffer = new byte[512]; int bytes; while ((bytes = input.read (buffer)) > 0) { output.write (buffer, 0, bytes); } input.close (); return output.toByteArray(); }
|
|
Last Updated ( Tuesday, 14 August 2007 )
|