diff --git a/src/xercesc/framework/LocalFileFormatTarget.cpp b/src/xercesc/framework/LocalFileFormatTarget.cpp
index 84b3d61caa0797c286853db0a23ed63390edee18..30f54c7253a22402197ff53692c96fd9a4130c37 100644
--- a/src/xercesc/framework/LocalFileFormatTarget.cpp
+++ b/src/xercesc/framework/LocalFileFormatTarget.cpp
@@ -113,7 +113,15 @@ void LocalFileFormatTarget::writeChars(const XMLByte* const toWrite
         fIndex += count;
       }
       else
+      {
+        if (fIndex)
+        {
+          XMLPlatformUtils::writeBufferToFile(fSource, fIndex, fDataBuf, fMemoryManager);
+          fIndex = 0;
+        }
+
         XMLPlatformUtils::writeBufferToFile(fSource, count, toWrite, fMemoryManager);
+      }
     }
 
     return;