- 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
Copying a File in java
Following Java program copies a file to another.
Program
import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class CopyExample { public static void main(String[] args) { FileInputStream ins = null; FileOutputStream outs = null; try { File infile = new File("C:\Users\TutorialsPoint7\Desktop\abc.txt"); File outfile = new File("C:\Users\TutorialsPoint7\Desktop\bbc.txt"); ins = new FileInputStream(infile); outs = new FileOutputStream(outfile); byte[] buffer = new byte[1024]; int length; while ((length = ins.read(buffer)) > 0) { outs.write(buffer, 0, length); } ins.close(); outs.close(); System.out.println("File copied successfully!!"); } catch(IOException ioe) { ioe.printStackTrace(); } } } }
Output
File copied successfully!!
- Related Articles
- Copying file using FileStreams in Java\n
- C Program for copying the contents of one file into another file
- Deleting a File in java
- Reading a Text file in java
- Create a temporary file in Java
- Copying or moving a tenant database in SAP HANA
- How to compress a file in Java?
- How to truncate a file in Java?
- Create a new empty file in Java
- File Permissions in java
- File Objects in Java
- What are the different ways of copying an array into another array in Java?
- Different techniques for copying objects in JavaScript
- Check whether a file is a directory in Java
- Writing a CSV file in Java using OpenCSV

Advertisements