private void button1_Click(object sender, EventArgs e)
{
string filename = "";
string strFile = "";
int index = 0;
do
{
int fileId = index++;
filename = string.Format("{0}.dat", Convert.ToString(fileId).PadLeft(4, '0'));
strFile = DbFunc.getConnectionWZ() + filename;
}
while (File.Exists(strFile));
// 打开文件 () , 或通过 File 创建立如:
FileStream fss = new FileStream(strFile, FileMode.CreateNew);
// 转换为字节 写入数据 ( 可写入中文 )
Byte[] info = new UTF8Encoding(true).GetBytes("This is some text in the file.");
// 字节数组 , 字节偏移量 , 最多写入的字节数
BinaryWriter w = new BinaryWriter(fss);
// 设置要写入的偏移量
fss.Position = 13;// fss.Length;
fss.Write(info, 0, info.Length); //这个也可以
Byte[] info1 = new UTF8Encoding(true).GetBytes("测试第二个");
// 字节数组 , 字节偏移量 , 最多写入的字节数
BinaryWriter w1 = new BinaryWriter(fss);
// 设置要写入的偏移量
fss.Position = 73;// fss.Length;
fss.Write(info1, 0, info1.Length); //这个也可以
w.Close();
fss.Close();
}