Namespaces
Variants
Actions

Reading Unicode files in JavaME

Jump to: navigation, search
SignpostIcon FloppyDisk 52.png
Article Metadata

Article
Created: senthilkumar05 (27 Dec 2007)
Last edited: hamishwillee (18 Jul 2012)
Warning.png
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) {}
This page was last modified on 18 July 2012, at 14:53.
113 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved