在j2me中读取txt文件数据

private void read()
{
InputStream is = null;
DataInputStream dis= null;
int numCount=0;

try
{
is=this.getClass().getResourceAsStream("/level"+Integer.toString(gameLevel)+".txt");
dis= new DataInputStream(is);
boolean flag = true;
byte[] b ={0};
byte temp=0;
while(dis.read(b,0,1)!=-1)
{
if(44==b[0]||13==b[0]||10==b[0])
{
if(44==b[0])
{
backMap[numCount/16][numCount%16]=temp-'0';
numCount++;
}
}
else
{
temp=b[0];
}
}
}

catch(Exception e)
{
e.printStackTrace();
}
finally
{
is= null;
dis=null;
}
}

其中,文本文件中是数字或者标点符号。不能出现其他的字符。开发环境为WTK

你可能感兴趣的:(j2me)