title: Getting a QByteArray from a QFile and writing it in the same file
body: <p>I am going to edit the contents of a file. I  am handling the file using <code>QFile</code>. Now, I want to read it in small chunks like 1024 bytes. So far, I did :</p>
  
  <pre><code>QFile file("~/samplefile");
  
  long long sizeoffile = file.size();
  
  size = size/1024;          ///*this is for loop size devoid by 1024 because I want to run loop filesize/1024  because in each cycle I read 1024 bytes **///
  QString contentsToBeErased = "sample";
  
  QString eraser = contentsToBeErased;
  
  eraser = eraser.fill('*');
  
  int pos = 0;               ////** This is the position of  'contentsToBeErased' in 1024 bytes(for each cycle)  **//
  
  QByteArray myByteArray;
  
  if(!file.open(QIODevice::ReadWrite | QIODevice::Text))
  return;
  for(long long i =0; i&lt;size; i++)
  {
    myByteArray = file.readLine(1025);   ////**1025 is used bcoz readline reads 1 less bytes**//
  
    int sizeArray = 0;
  
    QTextCodec *byteArraytoString = QTextCodec::codecForName("UTF-8");     //conevrting bytearray to string
  
    QString thisString = byteArraytoString-&gt;toUnicode(rohitarray);
  
      if(thisString.contains(contenttobeerased, Qt::CaseInsensitive))
          {
             int occurrence = thisString.count(contentsToBeErased,Qt::CaseInsensitive);
             for(int ii = 0; ii&lt;occurrence; ii++)
              {
                  pos = thisString.indexOf(contentsToBeErased, pos,Qt::CaseInsensitive);
                  thisString.replace(pos,contentsToBeErased.size(), erase);
                  pos = pos + contentsToBeErased.size() ;
              }
  
               myByteArray = thisString.toUtf8();
               sizeArray = myByteArray.length();
               QFile file1("~/samplefile");
               file1.open(QIODevice::WriteOnly);
               file1.write(myByteArray);
               file1.close();
            }
  }
  </code></pre>
  
  <p>This works fine for first attempt but in 2nd attempt, I failed to read next 1024 bytes with <code>readLine(1025);</code>. It reads the first 1024 bytes again. </p>
  
  <p>So my first problem is that I don't know how to increase the <code>readLine();</code> position to get the next 1024 bytes. </p>
  
  <p>And the 2nd problem is I don't know how to <code>write()</code> the 2nd byte array to file after writing first byte array, because if I only use <code>write()</code>, it will replace the previous byte array with next byte array. So how can I append the array at the end of the file?</p>