Create a dat file and read the data DAT file *. Dat can also be understood from the suffix meaning: data file, data file;
Some of the files can be opened using notepad tools, but they are not necessarily encrypted;
The following uses the C # tool to create a dat file and store it in binary sequence data. In this way, opening it with notepad is garbled and serves as a protection function.
First introduce: using system. IO;
Where to create: Write the following code
Create a BAT file:
Stream S = file. Open ("A. Bat", filemode. Create); // create a. BAT file. If an error occurs before the. BAT file is overwritten, then the file is created
Binaryformatter B = new binaryfitmatter (); // create a serialized object www.kanzhibotv.com
B. serialize (S, "data to be serialized"); // serialize the data to S
S. Close ();
/// Read www.k2tiyu.com
Read the BAT file:
Stream S = file. Open ("A. Bat", filemode. Open); // open the. BAT file
Binaryformatter B = new binaryfitmatter (); // create a serialized object
String SSS = (string) B. deserialize (s); // deserializes s to the original data format;
Public static void writedat (string pfiledat)
{
// Open a binary writer for the file
Filestream FS;
FS = new filestream (pfiledat + "\ bin \ binfile. dat", filemode. openorcreate, fileaccess. readwrite );
Binarywriter BW = new binarywriter (FS );
// Prepare different types of data
Int aint = 34567;
Int bint = 99999;
Int CINT = 11;
Long time = datetime. Today. tobinary ();
Char [] achararray = {'A', 'B', 'C '};
// Write data using multiple reloads of the write Method
Bw. Write (aint );
Bw. Write (bint );
Bw. Write (CINT );
Bw. Write (time );
Bw. Write (achararray );
FS. Close ();
Bw. Close ();
}