The following Java ME code demonstrates a method of reading resources from JAR file that is present on mobile handset. An example where this kind of application may be used is for example game developer wants to make an application for voice recognition. Simple sound files like one, two etc. are stored in a jared file and later can be accesed when they are to be compared.

 public class SoundDemo {
    private byte[] fileNameBuf;
    private byte[] buf=new byte[12*1000];
    Player player;
    public SoundDemo() {}
    public static InputStream soundStreams;
    // This method loads the sound
    public void loadSounds() throws IOException {
            // Reading resources of JAR file
            InputStream in = getClass().getResourceAsStream(
            if (in != null) {
                try {
                    int total = 0;
                    while (true) {
                        int numRead =,
                                total, buf.length-total);
                        if (numRead <= 0) {
                        total += numRead;
                    byte[] soundBuf = new byte[total];
                    System.arraycopy(buf, 0, soundBuf, 0, total);
                    soundStreams = new ByteArrayInputStream(soundBuf);
                    // Create player object
                    player = Manager.createPlayer(soundStreams, 
                } catch (Exception e) {} finally {
    public void doPlay() throws Exception {
        // Play the sound