J2ME and text files... or am I just stupid?

Started by
2 comments, last by Nick2048 20 years, 7 months ago
I would like to be able to read text (or binary) files from my JAR. It seems like loading images stored in the JAR is simple, but I have yet to find a way to load text files. I''ve looked at some of the docks that come with the Wireless Toolkit, but I can''t seem to find what I''m looking for. Then again, I''m also a little new to Java as well, which can''t help :S
Advertisement
Ok, I am just stupid. Maybe I''ll google BEFORE I post next time.

But, if anyone else is interested:
http://wireless.java.sun.com/midp/questions/res/
Hi!

One comment to the code snippet at wireless.java.sun:
Is it really good to create a String for each character ?
Perhaps its better to read more characters before adding to the StringBuffer, something like

try {            Class c = this.getClass();            InputStreamReader ir = new InputStreamReader(c.getResourceAsStream("/thisfile.txt"));            StringBuffer str = new StringBuffer();            char c[] = new char[255];            int numBytes;            while ( (numChars=ir.read(c,0,255)) != -1 ) {                str.append(c,0,numChars);            }            ir.close();            System.out.println(str);        }        catch (IOException e) {            e.printStackTrace();        }


Please note that i have not tested the code before posting it, but i think it will run.

McMc
----------------------------My sites:www.bytemaniac.com www.mobilegames.cc
That would probably help make it more efficient for sure. I figure they probably did the sample that way just to show how it could be done.

This topic is closed to new replies.

Advertisement