Index: src/main/java/org/geotools/data/shapefile/dbf/DbaseFileWriter.java
===================================================================
--- src/main/java/org/geotools/data/shapefile/dbf/DbaseFileWriter.java	(revision 34140)
+++ src/main/java/org/geotools/data/shapefile/dbf/DbaseFileWriter.java	(working copy)
@@ -23,6 +23,7 @@
 import java.io.UnsupportedEncodingException;
 import java.nio.ByteBuffer;
 import java.nio.MappedByteBuffer;
+import java.nio.channels.FileChannel;
 import java.nio.channels.WritableByteChannel;
 import java.nio.charset.Charset;
 import java.text.FieldPosition;
@@ -62,6 +63,7 @@
     private final Date NULL_DATE = new Date();
     private StreamLogging streamLogger = new StreamLogging("Dbase File Writer");
     private Charset charset;
+    private int recordCount=0;
     
     /**
      * Create a DbaseFileWriter using the specified header and writing to the
@@ -126,7 +128,7 @@
      *                 If the entry doesn't comply to the header.
      */
     public void write(Object[] record) throws IOException, DbaseFileException {
-
+    	recordCount++;
         if (record.length != header.getNumFields()) {
             throw new DbaseFileException("Wrong number of fields "
                     + record.length + " expected " + header.getNumFields());
@@ -217,7 +219,16 @@
         // buffer.position(0);
         // buffer.put((byte) 0).position(0).limit(1);
         // write();
+    	
         if (channel.isOpen()) {
+        	if (channel instanceof FileChannel) {
+        		// we can't update the header for a generic WritableByteChannel,
+        		// but at least we can do it for FileChannels
+        		header.setNumRecords(recordCount);
+        		FileChannel fc = (FileChannel) channel;
+        		fc.position(0);
+        		header.writeHeader(channel);
+        	}
             channel.close();
             streamLogger.close();
         }
