Create a large file

Source: Internet
Author: User

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>
/// Summary of form1.
/// </Summary>
Public class form1: system. Windows. Forms. Form
{
/// <Summary>
/// Required designer variables.
/// </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 ()
{
//
// Required for Windows Form Designer support
//
Initializecomponent ();

//
// Todo: add Any constructor code after initializecomponent calls
//
}

/// <Summary>
/// Clear all resources in use.
/// </Summary>
Protected override void dispose (bool disposing)
{
If (disposing)
{
If (components! = NULL)
{
Components. Dispose ();
}
}
Base. Dispose (disposing );
}

# Region code generated by Windows Form Designer
/// <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </Summary>
Private void initializecomponent ()
{
This. components = new system. componentmodel. Container ();
This. size = new system. Drawing. Size (300,300 );
This. Text = "form1 ";
}
# Endregion

/// <Summary>
/// Main entry point of the application.
/// </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 = 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 ");
}

}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.