在文本文件中搜索字符串

时间:2012-04-02 10:57:19

标签: android

我想在文本文件中搜索坐标的名称,然后使用x和y值。 我在Java编程中准备编程并且它工作正常,但是当我在eclipse中使用相同的方法时它给了我最后一个没有x和y的坐标名称

以下是代码:

    coordsuk1 =(EditText) findViewById(R.id.etJoin1);
    searchco1 =(Button) findViewById(R.id.bSearchCo1);
    searchco1.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            try{
                File myfile=new File("/sdcard/"+filename.getText().toString()+".txt");
                FileInputStream filein=new FileInputStream(myfile);
                BufferedReader br=new BufferedReader(new InputStreamReader(filein));

                String reel = br.readLine ();

                                int tel = reel.indexOf (" ");
                                naamsuk1 = reel.substring (0, tel);

                   while (!naamsuk1.equals (coordsuk1))
                   {

                          reel = br.readLine ();
                          tel = reel.indexOf (" ");
                          naamsuk1 = reel.substring (0, tel);
                   }

                   coordnaam1join = reel.substring (0, tel);
                   coordy1 = Double.parseDouble (reel.substring (10, 22));
                   coordx1 = Double.parseDouble (reel.substring (26, 36));

                Toast.makeText(getBaseContext(),
                        "Co ord '"+filename.getText().toString()+"' found",
                        Toast.LENGTH_SHORT).show();

            }
            catch(Exception e){
                Toast.makeText(getBaseContext(), e.getMessage(),Toast.LENGTH_SHORT).show();
            }
            joinIntv1.setText("coordsuk1: "+coordsuk1);
            joinIntv2.setText("naamsuk1: "+naamsuk1);

                            joinIntv3.setText("coordy1: "+coordy1);
            joinIntv4.setText("coordx1: "+coordx1);


        }
    });

o我得到一个空白的吐司。 文本文件如下所示:

AB -42537.4098 24263.8160

ST4 -42677.9017 24201.6750

WODRC -42428.8129 24151.9450

MGDM -42369.8561 24128.2079

0 个答案:

没有答案