Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Web;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. IO;
Public partial class Default3: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
}
Protected void button#click (object sender, EventArgs e)
{
String filename = Server. MapPath ("~ /") + This. TextBox2.Text;
FileStream fs = new FileStream (filename, FileMode. Create,
FileAccess. Write, FileShare. None );
StreamWriter sw = new StreamWriter (fs );
Sw. Write (this. TextBox1.Text );
Sw. Flush ();
Sw. Close ();
Fs. Close ();
} // Create a file
Protected void Button2_Click (object sender, EventArgs e)
{
String filename = Server. MapPath ("~ /") + This. TextBox2.Text;
FileStream fs = new FileStream (filename, FileMode. Open,
FileAccess. Read, FileShare. Read );
StreamReader sr = new StreamReader (fs );
This. TextBox1.Text = sr. ReadToEnd ();
Sr. Close ();
Fs. Close ();
} // Read the file
Protected void Button3_Click (object sender, EventArgs e)
{
String filename = Server. MapPath ("~ /") + This. TextBox2.Text;
FileStream fs = new FileStream (filename, FileMode. Create,
FileAccess. Write, FileShare. None );
BinaryWriter bw = new BinaryWriter (fs );
String [] data = this. TextBox1.Text. Split (new string [] {""},
StringSplitOptions. RemoveEmptyEntries );
Foreach (string str in data)
{
Bw. Write (Convert. ToInt32 (str ));
}
Bw. Close ();
Fs. Close ();
} // Create a binary file www.2cto.com
Protected void Button4_Click (object sender, EventArgs e)
{
String filename = Server. MapPath ("~ /") + This. TextBox2.Text;
FileStream fs = new FileStream (filename, FileMode. Open,
FileAccess. Read, FileShare. None );
BinaryReader br = new BinaryReader (fs );
Long nums = br. BaseStream. Length/4;
For (long I = 0; I <nums; I ++)
{
This. TextBox1.Text + = br. ReadInt32 (). ToString () + "";
}
Br. Close ();
Fs. Close ();
}
} Read Binary files
From blue-blue