Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Reading Unicode files in JavaME

From Wiki
Jump to: navigation, search
Article Metadata
Article
Created: senthilkumar05 (27 Dec 2007)
Last edited: hamishwillee (15 Oct 2013)

Warning.pngThis 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 article demonstrates how to read unicode files using Java ME. The following method reads the unicode file, returning a string with the file name:

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) {}
This page was last modified on 15 October 2013, at 04:02.
92 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×