title: Checking if a File is Blank in Android
body: <p>This is my code sample. The code is pretty long just to test if a file is blank and then if it isn't, write onto it. Either way, the line <code>if (!(data.equals("")) &amp;&amp; !(data.equals(null)))</code> doesn't work and even when the file is blank, it still goes through the Alert.</p>
  
  <pre><code>FileInputStream fIn = null;String data = null;InputStreamReader isr = null;
  try{
      char[] inputBuffer = new char[1024];
      fIn = openFileInput("test.txt");
      isr = new InputStreamReader(fIn);
      isr.read(inputBuffer);
      data = new String(inputBuffer);
      isr.close();
      fIn.close();
  }catch(IOException e){}
  
  // this is the check for if the data inputted from the file is NOT blank
  if (!(data.equals("")) &amp;&amp; !(data.equals(null)))
  {
      AlertDialog.Builder builder = new AlertDialog.Builder(Main.this);
      builder.setMessage("Clear your file?" + '\n' + "This cannot be undone.")
      .setCancelable(false)
      .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int id) {
              EditText we = (EditText)findViewById(R.id.txtWrite);
              FileOutputStream fOut = null;
  
              OutputStreamWriter osw = null;
              try{
                  fOut = openFileOutput("test.txt", Context.MODE_PRIVATE);
                  osw = new OutputStreamWriter(fOut);
                  osw.write("");
                  osw.close();
                  fOut.close();
                  we.setText("");
              }catch(Exception e){}
          }
      })
      .setNegativeButton("No", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int id) {
              dialog.cancel();
          }
      });
      AlertDialog alert = builder.create();
      alert.show();
  }
  </code></pre>
  
  <p>Also, if anyone has a way of shorting up this code, I would be greatful!</p>