<p>Ok, I am reading in dat files into a byte array.  For some reason, the people who generate these files put about a half meg's worth of useless null bytes at the end of the file.  Anybody know a quick way to trim these off the end?</p>

<p>First thought was to start at the end of the array and iterate backwards until I found something other than a null, then copy everything up to that point, but I wonder if there isn't a better way.</p>

<p>To answer some questions:
Are you sure the 0 bytes are definitely in the file, rather than there being a bug in the file reading code? Yes, I am certain of that.</p>

<p>Can you definitely trim all trailing 0s? Yes.</p>

<p>Can there be any 0s in the rest of the file? Yes, there can be 0's other places, so, no, I can't start at the beginning and stop at the first 0.</p>

Assuming 0=null, that is probably your best bet... as a minor tweak, you might want to use
```
Buffer.BlockCopy
```
when you finally copy the useful data..