Reading Unicode files in JavaME
Article Metadata
This article does not meet the wiki quality standards: Please make it more useful by adding links or additional information as discussed in the quality standards. When you have done so you can delete the {{NeedsMoreWork}} template from the article to remove this warning.
This Method is to read the unicode file, and it will return the String
public String readUnicodeFile(String filename) {
StringBuffer buffer = null;
InputStream is = null;
InputStreamReader isr = null;
try {
Class c = this.getClass();
is = c.getResourceAsStream(filename);
if (is == null) throw new Exception("File Does Not Exist");
isr = new InputStreamReader(is,"UTF8");
buffer = new StringBuffer();
int ch;
while ((ch = isr.read()) > -1) {
buffer.append((char)ch);
if (isr != null) isr.close();
}
}catch (Exception ex) {
System.out.println(ex);
}
return buffer.toString();
}
/**
* This Sample Midlet reads of the Unicode Characters and displays
*/
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;
import javax.microedition.midlet.MIDlet;
public class UnicodeTest extends MIDlet {
Display display;
Form form = null;
StringItem msg = null;
public UnicodeTest() {}
public void startApp() {
display = Display.getDisplay(this);
msg = new StringItem("'Hello World' in Japanese","u3053u3093u306Bu3061u306Fu4E16u754C");
form = new Form("Unicode Test");
form.append(msg);
display.setCurrent(form);
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}


(no comments yet)