title: How can I write to a MIFARE Classic tag?
body: <p>How can I write to a MIFARE Classic tag?</p>
  
  <p>I have written this code, but <code>writeBlock</code> results in the error "java.io.IOException: transceive failed".</p>
  
  <p>How can this be solved?</p>
  
  <pre><code>MifareClassic mfc = MifareClassic.get(mytag);
  boolean auth = false;
  mfc.connect();
  auth = mfc.authenticateSectorWithKeyA(1,MifareClassic.KEY_DEFAULT);
  if (auth) {
      String text = "Hello, World!";
      byte[] value  = text.getBytes();
      byte[] toWrite = new byte[MifareClassic.BLOCK_SIZE];        
  
      for (int i=0; i&lt;MifareClassic.BLOCK_SIZE; i++) {
          if (i &lt; value.length) toWrite[i] = value[i];
          else toWrite[i] = 0;
      }           
  
      mfc.writeBlock(2, toWrite);
  }
  </code></pre>