Namespaces
Variants
Actions

How to read a binary file from JAR

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 = input.read(); read >= 0; read = input.read())
output.write(read);
 
byte[] buffer = output.toByteArray();
 
input.close ();
output.close();
 
return buffer;
}
SignpostIcon FloppyDisk 52.png
Article Metadata

Tested with
Devices(s): Nokia 7373, Nokia N82

Compatibility
Platform(s): Series 40, Symbian
Device(s): MIDP2.0/CLDC 1.1

Article
Keywords: File, Binary, InputStream, ByteArrayOutputStream
Created: firt (15 Apr 2007)
Updated: tiviinik (17 Jan 2012)
Last edited: tiviinik (17 Jan 2012)
This page was last modified on 17 January 2012, at 14:16.
178 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved