Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 09:06, 27 November 2007.

How to read a binary file from JAR

From Forum Nokia Wiki

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 = input.read (buffer)) > 0) {
        output.write (buffer, 0, bytes);
    }
 
    input.close ();
    return output.toByteArray();
}
Related Discussions
Thread Thread Starter Forum Replies Last Post
using jpg instead of png??? farhanx Mobile Java Media (Graphics & Sounds) 13 2003-10-15 02:38
Preverifying and JARring? weedy Mobile Java General 2 2003-07-12 22:48
Jar / Jad.. xkenshin Mobile Java General 0 2004-04-28 07:58
how to read file ? xnew Mobile Java General 1 2003-03-24 08:23
N95 Invalid jar file jiali Mobile Java General 12 2008-06-29 14:04
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtopicQUqfnTopicZjavaQ
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX