Now i will share to you how to read text file in J2ME application. before that, you must know that every file on J2ME is same. they are treated as byte file. for example you want to read text file, so the application will open the file then read the byte value. thats it. so how can you display the text inside that file? you must convert into string by your self. this is how that algorithm work.
InputStream is = getClass().getResourceAsStream("/help.txt");
try {
StringBuffer sb = new StringBuffer();
int chr, i = 0;
while ((chr = is.read()) != -1)
sb.append((char) chr);
return sb.toString();
} catch (Exception e) {
}
you can see? the file is read as byte value, then you convert into string buffer, then you can convert into string and display into the form.
the case is same with the other file, for example you want to create your own extensions.
ok here is the code for you. try it. remember copy file help.txt into resource directory.
Subscribe To Retrieve Articles On Your Email Here
Post a Comment