SY-8-b Java program to copy the contents from one file to other file in easy way

Java program to copy the contents from one file to other file

Write a Java program to copy the contents from one file to other file.

We have used FileReader and FileWrite classes along with BufferedReader and BufferedWriter classes to perform this practical.

Java program for billing system

File name : itvoyagers.txt

Welcome to ITVoyagers...
Do visit itvoyagers.in for practical and notes.
Follow us on Instagram and Facebook.

File name : CopyContentDemo.java

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.util.*;
import java.io.*;

class CopyContentDemo
{
	static String copyfilename, pastefilename, contents;
	Scanner sc;
	public CopyContentDemo()
	{
		 sc = new Scanner(System.in);
	}

	public void getFilesName()
	{
		System.out.print(" Enter file name with extension (itvoyagers.txt) from where you want to copy the content : ");
		copyfilename = sc.nextLine();
		System.out.print("n Enter file name with extension (itvoyagers.txt) from where you want to paste the content : ");
		pastefilename = sc.nextLine();
	}
//itvoyagers.in
	public void copyContent()
	{
		try
        {
            FileReader cfr = new FileReader(copyfilename);
            FileWriter pfr = new FileWriter(pastefilename);

            BufferedReader cbr = new BufferedReader(cfr);
    		BufferedWriter pbr = new BufferedWriter(pfr);  
            
            while((contents = cbr.readLine()) != null)
            {
            	pbr.write(contents);
            	pbr.newLine();
            }

            cbr.close();
            pbr.close();

            System.out.println("n Conten of '" + copyfilename + "' file has been copied in '" + pastefilename + "' file.");
        }
        catch(IOException ex)
        {
            System.out.println("n Something went wrong!!! Please check forn 1. If the file name is correctn 2. The file '" + copyfilename + "' does not exist.");
        }
	}

	public static void main(String[] args)
	{
		CopyContentDemo rd = new CopyContentDemo();
		rd.getFilesName();
		rd.copyContent();
	}
}

Output

copy content from one file to another file in java itvoyagers

File name : demo.txt (After the program execution)

copy data from one file to another in java using bufferedreader itvoyagers

PRACTICALS/PRACTICE PROGRAM IN Java

SYIT Practical Programs
SY-1-a Easy Java program to print multiplication table
SY-1-b Easy program to print inverted pyramid pattern of stars in Java
SY-1-c Easy Java program to print the area and perimeter of a circle
SY-2-c Easy Java program to reverse a string
SY-3-a Easy Java program to count the letters, spaces, numbers and other characters
SY-3-c Easy to find the smallest and largest element from the array in Java
SY-4-a Easy java program to sort array in ascending and descending order
SY-4-b Easy program on constructor and destructor in Java
SY-4-c Implementation of abstract class in Java in easy way
SY-5-a Easy java program to implement single level inheritance
SY-5-b Easy java program to implement method overriding
SY-5-c Easy java program to implement multiple inheritance
SY-6-a Easy program to create package in Java
SY-6-b easy java program to add two matrices and print the resultant matrix
SY-6-c Java program for multiplying two matrices in easy way
SY-7-a easy java program to implement the vectors
SY-7-c Easy and simple java program to implement multithreading
SY-8-a java program to open a file and display the contents in the console window in easy way
SY-8-b Java program to copy the contents from one file to other file in easy way
SY-9-a Java AWT program to print the factorial for an input value in easy way
SY-9-b Java AWT program to perform various string operations in easy way
SY-9-c Easy java program to implement exception handling
SY-10-a Java AWT program to accept and display student details in easy way
ST-10-b Java program to design a calculator based on AWT application in easy way
SYCS Practical Programs Semester 3
Java program to solve quadratic equations to print the roots of ax2+bx+c=0
Java program to add two matrices
Accept n strings. Sort names in ascending order
Create a package: Animals. In package animals create interface Animal with suitable behaviors. Implement the interface Animal in the same package animals
Demonstrate Java inheritance using extends keyword.
Demonstrate method overloading and method overriding in Java.
Demonstrate creating your own exception in Java.
Using various swing components design Java application to accept a student’s resume. (Design form)
Write a Java List example and demonstrate methods of Java List interface.
Design simple calculator GUI application using AWT components
Write a Java program that takes a number as input and prints its multiplication table upto 10.
Java program to print reverse pyramid
Write a Java program to print the area and perimeter of a circle
SYCS Practical Programs Semester 4
SYCS-5 Java application to demonstrate servlet life cycle in easy way
Practice Program
1 – Best Java program to find factorial of a number
2 – Java program to check if number is Even or Odd
3 – Best Java program to check prime number
4 – Simple and easy Java program to calculate area
5 – Best Java program to convert decimal to binary
6 – Best Java program to implement stack using array
7 – Best Java program to check palindrome number
8 – Best Java program to reverse a number
9 – Easy and simple billing system program in java swing
10 – Easy and simple java program for billing system of tour and travels
More coming soon…

CHECKOUT OTHER RELATED TOPICS

We are aiming to explain all concepts of Java in easiest terms as possible.
ITVoyagers-logo
ITVoyagers
Author

Leave a Comment