HuyPV
Saturday, January 29, 2011
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();
}
// Usage:
String content = readUnicodeFile('/resource/huypv.txt');
Title:
J2ME - Read Unicode File From Resource
Description:
public String readUnicodeFile(String filename) { StringBuffer buffer = null; InputStream is = null; InputStreamReader isr = null; tr...
...
Rating:
4