Practice Exercises C# Sharp - Learn to program with performing exercises C# Sharp

Practice Exercises C# Sharp

Learn to program with performing exercises C# Sharp

File copier - Practice Exercises C# Sharp

Lesson 8:

File management

Exercise 8.25:

File copier


Create a program to copy a source file into a destination file. You must use FileStream and a block size of 512 Kb. An example of use might be:

mycopy file.txt e:\file2.txt

It must behave correctly if the source file does not exist and it must warn (but not overwrite it) if the destination file exists

Source Code:

using System;
using System.IO;
public class FileCopier

    public static void Main()
        const int BUFFER_SIZE = 512 * 1024;

        byte[] data = new byte[BUFFER_SIZE];

        FileStream inFile = File.OpenRead("1.exe");
        FileStream outFile = File.Create("1-copy.exe");

        int amountRead;

            amountRead = inFile.Read(data, 0, BUFFER_SIZE);
            outFile.Write(data, 0, amountRead);
        while (amountRead == BUFFER_SIZE);

Exercisey 8.25

Privacy Policy:

Google uses associated advertising companies to serve ads when it visits our website. These companies may use the information they obtain from your visits to this and other websites (not including your name, address, email address, or phone number) to provide you with announcements about products and services that interest you. If you would like to learn more about this practice and know your options to prevent these companies from using this information. Click in... Privacy and Terms of Google.


This site uses Google cookies to provide its services, to personalize advertisements and to analyze traffic. Google receives information about your use of this website. More information in... Privacy and Terms of Google.