title: Comparing txt file with input String in Android
body: <p>I have created a txt file and saved it in the file Explorer at <code>data/data/com.xxx/files/mynote/txt</code> when I entered a string into edit text and click the button. </p>
  
  <p>I want compare txt file content and input String.  In my txt file, only minimum length 5 to 6 is stored. How do I do this? I have tried but it can not compare properly - it goes to else block part when I entered the same string as i save in my txt file like "tazin".</p>
  
  <p>Here is my code.</p>
  
  <pre><code>  btnSubmitCode=(Button)findViewById(R.id.button_Submit);
          btnSubmitCode.setOnClickListener(new OnClickListener() {
  
          @Override
              public void onClick(View arg0) {
                  // TODO Auto-generated method stub
  
              if(editText_Code.getText().toString().isEmpty()) 
                  {
                      Toast.makeText(getApplicationContext(),"Please Enter Code", Toast.LENGTH_SHORT).show();
                  }
                  else
                  {
                      String strCode = editText_Code.getText().toString().trim();
                      create_File(strCode);
                      readFile();
                  }
  
                  String temp;
                  String searchString = "tazin";
  
                  try {
                      File file=new File("/data/data/com.xxxxx/files/mynote.txt/");
  
                      BufferedReader in = new BufferedReader(new FileReader(file));
                      while (in.readLine() != null)
                      {
                          temp = in.readLine();
                          System.out.println("String from txt file ="+temp);
                          if(searchString.equals(temp))
                          {
                              System.out.println("word is match");
                              in.close();
                              return;
                          }
                          else
                          {
                              System.out.println("word is not match");
                          }
                      }
                      in.close();
  
                  } 
  
                   catch (IOException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
              }
          });
  
  
  
  
  //Write File
      private void create_File(String strtext)
      {
          FileOutputStream fos = null;
          try
          {
              fos = openFileOutput("mynote.txt", MODE_PRIVATE);
              fos.write(strtext.getBytes());
              Toast.makeText(getApplicationContext(), "File created succesfully",
                      Toast.LENGTH_SHORT).show();
  
          }
          catch(FileNotFoundException fexception)
          {
              fexception.printStackTrace();
  
          }
          catch(IOException ioexception)
          {
              ioexception.printStackTrace();
          }
  
          finally
          {
              if (fos != null) 
              {
                  try 
                  {
                      // drain the stream
                      fos.flush();
                      fos.close();
                  }
                  catch (IOException e) 
                  {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
              }
          }
      }
  
  
      //Read File
  
      private void readFile()
      {
  
  
          FileInputStream fis;
  
          try 
          {
              fis = openFileInput("mynote.txt");
              byte[] reader = new byte[fis.available()];
              while (fis.read(reader) != -1) 
              {
  
              }
  
  
              textView_ReadCode.setText(new String(reader));
              strReadFile = new String(reader);
              System.out.println("Read File Into String Format " + strReadFile);
  
  
              Toast.makeText(getApplicationContext(), "File read succesfully",
                      Toast.LENGTH_SHORT).show();
  
              if (fis != null)
              {
                  fis.close();
              }
          } 
          catch (FileNotFoundException e)
          {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
          catch (IOException e)
          {
              Log.e("Read File", e.getLocalizedMessage());
          }
  
      }
  </code></pre>