cndavy

导航

 

private void loadLocationFile(int resourceID)
 {
  //注解2
  Resources res = this.getResources();
  InputStream in = null;
  BufferedReader br = null;

  try
  {
   in = res.openRawResource(R.raw.location_a0 + resourceID);
   String str;
   br = new BufferedReader(new InputStreamReader(in, "GBK"));
   while ((str = br.readLine()) != null)
   {
    //手机号码特征值为前7位
    String number = str.substring(0, 6);
    //手机号码归属地从第24位开始到最后
    String city = str.substring(24, str.length());
    
    //将数据写入数据库当中
    m_db.insert(DBHelper.TABLE_NAME,
       new String[] { DBHelper.NUMBER, DBHelper.CITY, DBHelper.LOCATION },
       new String[]{ number, city, DBHelper.LOCATIONS[resourceID] });
    
    Message msg = new Message();
    Bundle bundle = new Bundle();
    bundle.putString("number", "手机号码特征数据:" + number);
    bundle.putString("city", "手机号归属地城市:" + city);
    bundle.putString("location", "手机号码省级运营商:" + DBHelper.LOCATIONS[resourceID]);
    msg.setData(bundle);
    handler.sendMessage(msg);
    
    Log.v("xuanyusong", "手机号码特征数据:" + number + " 手机号归属地城市:" + city + " 手机号码省级运营商:" + DBHelper.LOCATIONS[resourceID]);
   }
  } catch (NotFoundException e)
  {
   Toast.makeText(this, "文本文件不存在", 100).show();
   e.printStackTrace();
  } catch (UnsupportedEncodingException e)
  {
   Toast.makeText(this, "文本编码出现异常", 100).show();
   e.printStackTrace();
  } catch (IOException e)
  {
   Toast.makeText(this, "文件读取错误", 100).show();
   e.printStackTrace();
  } finally
  {
   try
   {
    if (in != null)
    {
     in.close();
    }
    if (br != null)
    {
     br.close();
    }
   } catch (IOException e)
   {
    e.printStackTrace();
   }

  }
 }

posted on 2012-06-19 14:56  cndavy  阅读(631)  评论(0编辑  收藏  举报