J2ME and Unicode - Read Unicode File
(Page 4 of 6 )
The next step in module code separation would be to load language definitions from an external source. One option would be to read in language definitions from a text file, more appropriately a Unicode file. Here is a method you can use to read a Unicode text file:
To create a test file you can use the free application, Simredo, from http://www4.vc-net.ne.jp/~klivo/sim/simeng.htm
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();
}
Next: Reading a Text File with Unicode Codes >>
More Java Articles
More By Jason Lam