---
title: "Copy content of one file to another file using java"  
description: "In this blog I am providing you the code for Copying content of one file to another file using java.  Below line of code is help to copy the content o"  
author: "Vijay Shukla"  
published: 2013-10-04  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/603/copy-content-of-one-file-to-another-file-using-java  
category: "java"  
tags: ["java"]  
reading_time: 1 minute  

---

# Copy content of one file to another file using java

In this [blog](https://www.mindstick.com/articles/12705/myths-and-misconception-about-blog) I am providing you the [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) for Copying [content of one](https://www.mindstick.com/forum/118/problem-in-display-content-of-one-page-to-another-page) [file](https://www.mindstick.com/articles/59/encrypting-and-decrypting-files-using-c-sharp) to another file using java.\

Below line of code is help to [copy](https://www.mindstick.com/forum/161993/explain-the-numpy-array-copy-vs-view-with-example) the content of [source](https://www.mindstick.com/interview/840/what-happens-if-the-both-source-and-destination-are-named-same) file to [destination](https://yourviews.mindstick.com/story/1451/gorgeous-locations-for-destination-weddings-in-india) file.

```
import java.io.*;public class CopyClass {   public static void main(String[] args){   try     {      InputStream in = new FileInputStream      (new File("Source File"));      OutputStream out = new FileOutputStream      (new File("Destination File"));      byte[] buf = new byte[1024];      int len;
      while ((len = in.read(buf)) > 0) {         out.write(buf, 0, len);                System.out.println("File copied successfully!");
      }      in.close();      out.close();      BufferedReader in1 = new BufferedReader      (new FileReader("destnfile"));      String str;      while ((str = in1.readLine()) != null) {         System.out.println(str);      }      in.close();    }    catch(Exception ex){}}
}
```

\

**Note**: - Before run above code you [must](https://www.mindstick.com/articles/12978/top-reasons-why-every-magento-ecommerce-store-must-opt-for-mobile-app) be sure your source and destination file is available or not if this file is not available then you must create above file.

---

Original Source: https://www.mindstick.com/blog/603/copy-content-of-one-file-to-another-file-using-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
