• Call Us: +91 9437911966
  • Email Us: info@studentstutorial.com
  • Home
  • C Examples
  • Server Side
    • PHP
    • Java
    • CodeIgniter
    • Laravel
    • JSP
    • JDBC
  • Frontend
    • HTML
    • CSS
    • Javascript
    • jQuery
    • AJAX
    • FPDF
    • TCPDF
  • APP & DB
    • Android
    • Cordova
    • SQL
    • Oracle
  • Project
Java Introduction System.out.println(): Program for input through console Program for addition Program for Subtraction Program for Multiplication Program for Division Program for modulus Program for increment Program for percentage Program for square Program for cube Program for square root Check Even or Odd Reverse of a number Find prime numbers Find factorial Program for palindrome Program for Diamond Star Program for Pascal Star Program for Fibonacci Series Find largest number Find Smallest number Find largest third number Find largest second number Program for Bubble Sort Program for Insertion Sort Program for Selection Sort Program for Linear Search Program for Binary Search Find IP address Open notepad through java program Find Armstrong Number Find mirror clock Comparing Value create Backup file Program for file content modifier Program for copying files Fahrenheit to Celsius create deadlock program Implement hashcode program Convert File to Zip Remove Duplicate Element From Array Java Matrix Addition Java Matrix Multiplication

Java program for copying files

  • Students Tutorial
   

FileCopyUsingFOS.java

import java.io.*;
class FileCopyUsingFOS 
{
	public static void main(String[] args) throws FileNotFoundException, IOException
	{
		// Declare the variables
		FileInputStream fis = null;
		FileOutputStream fos = null;
		int fileSize = 0, data = 0;
        
		// Initialize the variables
		fis = new FileInputStream("source.txt");

		// Check in that  file data is available or not
		fileSize = fis.available();
		if (fileSize == 0)
		{
			System.out.println("Sorry, this file is empty.");
			fis.close();
			return;
		}

		// If file is not empty, initialse fos
		fos = new FileOutputStream("dest.txt");

		while ( (data = fis.read()) != -1)
		{
			fos.write(data);
		}

		// store the value from buffer to dest file
		fos.flush();

        System.out.println("File Copied.");
		// close the connection
		fos.close();
		fis.close();
	}
}

Student Tutorial is a online tutorial for web design and development. Here you can find easy example and explanation for each tutorial.
Copyright © 2016-2025 Student Tutorial

Server Side

  • PHP
  • Java
  • CodeIgniter
  • Laravel
  • JSP
  • JDBC

Frontend

  • HTML
  • CSS
  • Javascript
  • jQuery
  • AJAX
  • FPDF

App & Database

  • Android
  • Cordova
  • SQL
  • Oracle