Practice Exercises Java - Learn to program performing exercises with Java

Practice Exercises Java

Learn to program performing exercises with Java

12 Lessons Java with the Solutions - 228 Exercises Java with the solutions
For Beginners, Intermediates and Advanceds

App Practice Exercises Java

The human knowledge belongs to the world
¡The infomation should be free!

File copier - Practice Exercises Java

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:

public class Main
    public static void main(String[] args)
		final int BUFFER_SIZE = 512 * 1024;

		byte[] data = new byte[BUFFER_SIZE]; inFile = File.OpenRead("1.exe"); outFile = File.Create("1-copy.exe");

		int amountRead;

			amountRead =, 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.