如何制作简单的字典J2ME
我是 JavaME 初学者。我想做一个简单的字典。源数据放置在“res”目录中的“data.txt”文件中。结构是这样的:
#apple=水果种类;
#菠菜=一种蔬菜;
流程就这么简单。用户在文本字段中输入要搜索的单词,例如“apple”,系统接受用户输入,读取“data.txt”,在其中搜索匹配的单词,取出相应的单词,并将其显示到另一个文本字段/文本框。
我已经设法使用此代码读取整个“data.txt”..
private String readDataText() {
InputStream is = getClass().getResourceAsStream("data.txt");
try {
StringBuffer sb = new StringBuffer();
int chr, i=0;
while ((chr = is.read()) != -1)
sb.append((char) chr);
return sb.toString();
}
catch (Exception e) {
}
return null;
}
但我仍然不知道如何拆分它,找到与用户输入匹配的单词并获取相应的单词。希望有人愿意分享他/她的知识来帮助我..
I am beginner in JavaME. I'd like to make simple dicitionary. The source data is placed on "data.txt" file in "res" directory. The structure is like this:
#apple=kind of fruit;
#spinach=kind of vegetable;
The flow is so simple. User enters word that he want to search in a text field, e.g "apple", system take the user input, read the "data.txt", search the matched word in it, take corresponding word, and display it to another textfield/textbox.
I've managed to read whole "data.txt" using this code..
private String readDataText() {
InputStream is = getClass().getResourceAsStream("data.txt");
try {
StringBuffer sb = new StringBuffer();
int chr, i=0;
while ((chr = is.read()) != -1)
sb.append((char) chr);
return sb.toString();
}
catch (Exception e) {
}
return null;
}
but I still dont know how to split it, find the matched word with the user input and take corresponding word. Hope somebody willing to share his/her knowledge to help me..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基本上你想要这样的东西:
=
标记分割行Basically you want something like this:
BufferedReader
, no need to handle singlechar
s.=
token