Sign in to follow this  
Grantyt3

Erase Text in a File

Recommended Posts

In C#, can you erase all the text from a txt file? Also, I'm currently saving the highscores in my game to a text file, but I've notice that with most games, saves are saved to a file that isn't a txt file. It's like a binary file or something... all I know is, if you open it in a notepad, it just shows a bunch of symbols and junk, lol. Anyways, how do you save scores into a file like that?

Share this post


Link to post
Share on other sites
Erase all of the text from a text file... or in fact, erasing everything from an existing file:

If you just want to empty the file and don't care about dangling sectors on the hard drive, just open the file for CreateNew and then close it.

If you want to make sure that nobody can recover the data from leftovers on the hard drive, open the file for existing reading and writing, get the file length, then write new string(' ', fileLen); to it, then close it.


If you want to write binary to a file, look at the classes "BinaryWriter" and "BinaryReader". Those classes piggy-back on top of a FileStream (or in fact any other Stream) and let you say things like "ReadInt32();" or "Write(value);" in binary form in a file.

Share this post


Link to post
Share on other sites
It'll be easy to find out.

* Look for a game on your computer.
* COPY to some other directory a save file (it usually has either a character name or a time as the title)
(I only know how to do this on windows)
* Open up Windows Explorer and under "Tools" click "Folder Options...".
* Go into "View" and make sure "Hide file extensions for known types" isn't checked.
* Get your COPIED save file and right click and "Rename"
* Change the extension to *.txt
* Open the file

If its a bunch of squares with random letters then its binary.

Although if you can't be bothered finding out, I recon most game save files will be because otherwise it would be easy to open and edit your characters level and such.

Share this post


Link to post
Share on other sites
An easier way.

* Download Hex Editor
* Open save file

If it looks like gibberish it could also be encrypted, I mean you have to store the name and score somehow.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this