SoFunction
Updated on 2025-03-07

Simple example of C# file operation

Reading of files
Copy the codeThe code is as follows:

 FileStream fs = new FileStream(@"D:\", );
            byte[] buffer = new byte[1024 * 1024];
            (buffer, 0, );
            string content = (buffer);
            = content;
            ();

Save file
Copy the codeThe code is as follows:

 SaveFileDialog sfd = new SaveFileDialog();
            DialogResult rst = ();
            if(rst==)
            {
                FileStream fs = new FileStream(,);
                string content = ;
                byte[] buffer = ASCIIEncoding.(content);
                (buffer,0,);
                ();

Copying of files
Copy the codeThe code is as follows:

FileStream streamread = new FileStream(@"D:\",);
            FileStream streamwrite = new FileStream(@"F:\",);
            byte[]buffer=new byte[1024*1024*3];
            int Length;
            do
            {
                Length = (buffer,0, );
                (buffer,0, Length);
            }
            while (Length == );
            ();
            ();
            ("Copy Success");