WAP之家:为您提供最全最新的WAP技术,CP.SP.3G等行业资讯。 WAP之家交流论坛全新开放 点击进入>>
WAP资讯 | 3G动态 | SP动态 | 运营商动态 | 内容商动态 | 制造商动态 | 论坛讨论>> 每次自动访问
WAP技术 | WAP源码 | 手机编程 | 手机源码 | 无线技术 | J2ME技术 | 手机软件 添加到收藏夹
IVR技术 | SP资料 | SMS MMS技术 | 商业方案 | IVR下载 | 书籍教程 | 工具软件 语言:繁體中文

WAP之家技术文章J2ME技术程序开发j2me中读写文件查找的实例

j2me中读写文件查找的实例
作者:不详  来源:本站整理  发布时间:2005-11-25 13:28:02

String word_input = "wrap";
String word_search = null;

private void search ()
{
InputStream in = null;
byte[] buffer1 = new byte[259737];
byte[] word = new byte[20];
//System.out.println(word.length);
int kk = 0;
int position = 0;
int line = 1;
int temp_line = 100000;
int flag = 0;
try
{
word = word_input.getBytes();
//System.out.println(word.length);
in = getClass().getResourceAsStream("/cet4.txt");
in.read(buffer1);
//System.out.println(buffer1.length);
in.close();
}
catch (Exception e)
{
System.out.println("error!");
}
for (int ii = 0; ii < buffer1.length - 20; ii++)
{
if (buffer1[ii] == '\n')
{
line++;
}
for (int jj = 0; jj < word.length; jj++)
{
if (buffer1[ii + jj] == word[jj])
{
kk++;
}
}
if (kk == word.length)
{
if (flag == 0)
{

position = ii;
try
{
word_search = new String(buffer1, position, word.length, "UTF-8");
}
catch (Exception e)
{
System.out.println("new string() error");
}
System.out.println(word_search);
System.out.println(line);
temp_line = line;
//break;
flag ++ ;
}
}
else
{
kk = 0;
}
if (line == temp_line + 1)
{
try
{
word_search = new String(buffer1, position + word.length + 1, ii - position - word.length - 2, "UTF-8");
}
catch (Exception e)
{
}
System.out.println(word_search);
break;
}
if (ii == buffer1.length - 21)
{
System.out.println("no word");
break;
}
}

} // search() end!!!

[] [返回上一页] [打 印]
文章评论

用户名: 查看更多评论

分 值:100分 85分 70分 55分 40分 25分 10分 0分

内 容:

         (注“”为必填内容。) 验证码: 验证码,看不清楚?请点击刷新验证码