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.

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 to 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();
for (int read =; read >= 0; read =
byte[] buffer = output.toByteArray();
input.close ();
return buffer;
Article Metadata
Tested with
Devices(s): Nokia 7373, Nokia N82
Created: firt (15 Apr 2007)
Updated: tiviinik (17 Jan 2012)
Last edited: hamishwillee (30 Jul 2013)
This page was last modified on 30 July 2013, at 05:41.
77 page views in the last 30 days.