Dear experts, May I know how to read data from a text file(abc.txt) and print it inside a TextBox on a MIDlet? I have try DataOInputStream and FileInputStream and there is always error. Can you guys please kindly teach me how to do it? Thanks alot, Franco
john muchow
Ranch Hand
Joined: Mar 24, 2001
Posts: 49
posted
0
Here is a simple block of code to read a file InputStream is = getClass().getResourceAsStream("help.txt"); try { StringBuffer sb = new StringBuffer(); int chr, i = 0; // Read until the end of the stream while ((chr = is.read()) != -1) sb.append((char) chr); return sb.toString(); } catch (Exception e) { System.out.println("Error"); } In order for this to work, the file ("help.txt") will need to be packaged with the MIDlet in the JAR file. John Core J2ME Technology and MIDP [ January 18, 2002: Message edited by: john muchow ]