Xing, I believe you must have a file open for writing, and then you overwrite the beginning of the file, but you don't truncate the file first. You end up with what you have there.
As for the detatch() vs. removeContent(...), the detatch will be faster, but is not what's causing your problem here.
Can you provide more detail on how you open and write to the file?
EDIT: excellent. Your Files.newOutputStream(....) method call needs to have the TRUNCATE_EXISTING option set as well as the WRITE OPTION.