Concatenate & Buffer File in Java

Concatenate: It is possible to concatenate two or more files and save in a different file.

In java, by using SequenceInputStream class we can concatenate two or more files.

Buffer Files: In java, we can create a buffer to store temporary data that is read from & written to a stream and this process known as i/o buffer operation.

Buffer is  sit between programmer and source/destination file.

Buffer can be created by using following classes:

  • BufferedInputClass
  • BufferedOutputClass

Example: write a program to concatenate two file A & B and concatenated data print on output screen.

Suppose we have a File “A.txt”

Hello students I am aditya.  

 and                         File “B.txt”

Hello  

Output: Hello students I am aditya.                                                                                           Hello

Example: Write a program to copy the content of one file to another file using buffer/BufferReader.                                                                

Suppose we have a File “A .txt”                               

Hello students I am aditya.  

Output:                                              File “B”

Hello students I am aditya.  

Note: If there is no file “B” it will be create automatically.

Example: Write a program to concatenate two file A & B and save the concatenated data on a file C.

Suppose we have a File “A.txt” and File “B.txt”

Hello students I am aditya.  
Hello  

Output:               File “C”

Hello students I am aditya. Hello  

Note: Ifthere is no file “C” it will be create automatically.