创建大文件
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Threading;
using System.Diagnostics;
namespace WindowsApplication1
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public static bool Writing = false;
public static string filename = @"c:\1.dat";
static byte index = 10;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
for(int i=0;i<1;i++)
{
//File.Create("c:\\AA",1024*1024*1024);
//FileInfo aa=new FileInfo("c:\\AA");
//FileStream fs=new FileStream(
StreamWriter sw=new StreamWriter("c:\\AA",true,System.Text.Encoding.UTF8,1024*1024);
}
for(byte i = 0; i < 3; i++)
{
WriteFile();
// ThreadStart strat = new ThreadStart(WriteFile);
// Thread thread = new Thread(strat);
// thread.Start();
}
Application.Run(new Form1());
}
public static void WriteFile()
{
index++;
byte num = index;
byte[] bytes = new byte[1024*1024*1024];
for(int i = 0; i < 1024; i++ )
{
bytes[i] = num;
}
while(Writing == true)
{
Application.DoEvents();
}
Writing = true;
FileStream fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write);
fs.Seek((num -1) * 1024, 0);
fs.Write(bytes, 0, bytes.Length);
fs.Close();
Writing = false;
Debug.WriteLine(num+"end");
}
}
}