- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 Articles
- Golang program to copy one file into another file
- Java Program to copy value from one list to another list
- C program to copy the contents of one file to another file?
- How to read data from one file and print to another file in Java?
- How to copy a collection from one database to another in MongoDB?
- How to copy a table from one MySQL database to another?
- How can I copy a file from one folder to another folder within a container in Docker?
- Copy all the elements from one set to another in Java
- How do you copy an element from one list to another in Java?
- Moving a file from one directory to another using Java
- How to copy rows from one table to another in MySQL?
- C# program to copy a range of bytes from one array to another
- Java Program to copy all the key-value pairs from one Map into another
- How to Copy File Permissions and Ownership to Another File in Linux?
- How to copy files from one folder to another using Python?

Advertisements