

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to write a program to copy characters from one file to another in Java?
To copy the contents of one file to other character by character
Example
import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class CopyFiles { public static void main(String[] args) throws IOException { //Creating a File object to hold the source file File source = new File("D:\ExampleDirectory\SampleFile.txt"); //Creating a File object to hold the destination file File destination = new File("D:\ExampleDirectory\outputFile.txt"); //Creating an FileInputStream object FileInputStream inputStream = new FileInputStream(source); //Creating an FileOutputStream object FileOutputStream outputStream = new FileOutputStream(destination); //Creating a buffer to hold the data int length = (int) source.length(); byte[] buffer = new byte[length]; while ((length = inputStream.read(buffer)) > 0) { outputStream.write(buffer, 0, length); } inputStream.close(); outputStream.close(); System.out.println("File copied successfully......."); } }
Output
File copied successfully.......
- Related Questions & Answers
- C program to copy the contents of one file to another file?
- Java Program to copy value from one list to another list
- How to copy a table from one MySQL database to another?
- How to copy a collection from one database to another in MongoDB?
- Moving a file from one directory to another using Java
- C# program to copy a range of bytes from one array to another
- How to read data from one file and print to another file in Java?
- How to copy rows from one table to another in MySQL?
- Copy all the elements from one set to another in Java
- How to copy files from one folder to another using Python?
- How to copy files from one server to another using Python?
- Copy values from one array to another in Numpy
- How do you copy an element from one list to another in Java?
- How can we copy one array from another in Java
- Java Program to copy all the key-value pairs from one Map into another
Advertisements