Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Revision as of 12:14, 5 June 2009 by tanjaluodes (Talk | contribs)

How to read a binary file from JAR

From Wiki
Jump to: navigation, search

If you want to read a binary file from JAR file (read only), for example a game level, a map, or any data information you have to:

  • Include the data file in your project, so the IDE can append it to the JAR package.
  • Use the following code to read a binary file from the JAR
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 = (buffer)) > 0) {
output.write (buffer, 0, bytes);
input.close ();
return output.toByteArray();
52 page views in the last 30 days.