读取TXT文档并显示的问题
本人刚学J2ME,请高手帮忙.
TXT文档格式如下:
啊 a1
阿 a2
......
唉 ai1
就是一个拼音与汉字的对应表,想从表中读取这些信息逐行显示。代码如下,但有报错。
public class ReadDate extends MIDlet{
private Display display;
private TextBox textBox;
public ReadDate(){
display=Display.getDisplay(this);
String s= "sadfsdf ";
String str = " ";
textBox=new TextBox( "display ",str,50,0);
InputStream in = this.getClass().getResourceAsStream( "pinyinbiao.txt ");
int c;
ByteArrayOutputStream bais = new ByteArrayOutputStream();
try {
while((c=in.read())!= -1)
{
bais.write(c);
}
byte data[] = bais.toByteArray();
str = new String(data, "utf-8 ");
} catch (
IOException e) {
e.printStackTrace();
}
}
protected void startApp(){display.setCurrent(textBox);}
protected void destroyApp(boolean unconditional){}