You'd also need to properly calculate the checksum, otherwise the file will reset no matter what. I explain how to do this in one of the first comments on this issue (I figured out that you use null in place of missing map.txt hashes).
Someone informed me that he thinks this one stat is causing the whole problem:
{"16843110"} -> "Map (Times Crafted)".
I don't have the time to test it myself tonight, but I'll try removing it from my stats tomorrow to see if it fixes it.
That's what I was trying to do, but I don't know how Minecraft calculates the checksum when there are statistics without an associated MD5 in map.txt (the details of this generation are explained in my comment above). If I knew how Minecraft did it, I could simply port the old one over to the new one and keep all of my statistics. Or, in my case, just add the values from my pre-1.4 backup to the values in the new post-1.4 file to get a full, up-to-date statistics file.
I looked into the issue and it seems to be related to the fact that there are no MD5 hashes for newer achievements and blocks in map.txt in the achievement folder of minecraft.jar. There is a "checksum" value in the stats .dat file, and if this is incorrect, Minecraft empties the file. The checksum is the MD5 hash of the values in the following format:
local<HASH>,value,<HASH>,value,<HASH>,value, ...
So if your only statistic is 10 worlds loaded (Worlds Loaded's id is 1002, and 1002's associated hash in map.txt is d517ae73160fd8576d7687ead1c1a973:
locald517ae73160fd8576d7687ead1c1a973,10,
The hash of that string is 4c9841b44dca5b5667d220471ab70817, and that is what is used as the checksum value.
map.txt in minecraft.jar is a list of MD5s and statistics ids. The string starts with "local", then includes the id-hash and value of each statistic/achievement. But there are no hashes for any achievement id over 5242895 (newer achievements go up to 5242903 or so), and no hashes for any block introduced after the achievement system was added, such as Melon blocks. Obviously Minecraft knows how to handle these missing hashes since statistics for these blocks/achievements were stored prior to 1.4, but it may have something to do with the statistics-wiping of 1.4.
I attached an example of a stats file that will be wiped upon loading Minecraft 1.4. Remember to change the filename from "Player" to your username to make Minecraft actually handle it.
I just tested it for myself and it's definitely that one single stat that broke the whole file. It must be because 1.4 made crafting maps themselves impossible, and you now create empty maps instead. The new maps-crafted stat has moved to ID 16843147 (for item ID 395, Empty Map). So an easy fix would be to scan for 16843110 on game load, and if it's found, replace it with 16843147. Credit for the find goes to Valares on the Minecraft Forum: http://www.minecraftforum.net/topic/1536225-stats-reset-with-14/