Question: I am reading a video file data in bytes and sending to another file but the received video file is not playing properly and is chattered.

Can anyone explain me why this is happening and a solution is appreciated.

My code is as follows

```
import java.io.*;

public class convert {

  public static void main(String[] args) {

    //create file object
    File file = new File("B:/music/Billa.mp4");

    try
    {
      //create FileInputStream object
      FileInputStream fin = new FileInputStream(file);

       byte fileContent[] = new byte[(int)file.length()];
       fin.read(fileContent);

       //create string from byte array
       String strFileContent = new String(fileContent);

       System.out.println("File content : ");
       System.out.println(strFileContent);

       File dest=new File("B://music//a.mp4");
       BufferedWriter bw=new BufferedWriter(new FileWriter(dest));
       bw.write(strFileContent+"\n");
       bw.flush();

    }
    catch(FileNotFoundException e)
    {
      System.out.println("File not found" + e);
    }
    catch(IOException ioe)
    {
      System.out.println("Exception while reading the file " + ioe);
    }
  }
}

```

Answer: 
This question might be dead but someone might find this useful.

You can't handle video as string. This is the correct way to read and write (copy) *any* file using Java 7 or higher.

Please note that size of buffer is processor-dependent and usually should be a power of 2. See [this answer](https://stackoverflow.com/a/16068166/6561533) for more details.

```
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class FileCopy {
public static void main(String args[]) {

    final int BUFFERSIZE = 4 * 1024;
    String sourceFilePath = "D:\\MyFolder\\MyVideo.avi";
    String outputFilePath = "D:\\OtherFolder\\MyVideo.avi";

    try(
            FileInputStream fin = new FileInputStream(new File(sourceFilePath));
            FileOutputStream fout = new FileOutputStream(new File(outputFilePath));
            ){

        byte[] buffer = new byte[BUFFERSIZE];

        while(fin.available() != 0) {
            bytesRead = fin.read(buffer);
            fout.write(buffer, 0, bytesRead);
        }

    }
    catch(Exception e) {
        System.out.println("Something went wrong! Reason: " + e.getMessage());
    }

    }
}

```
```
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;

import javax.imageio.ImageIO;

public class Reader {

    public Reader() throws Exception{

        File file = new File("C:/Users/Digilog/Downloads/Test.mp4");

        FileInputStream fin = new FileInputStream(file);
        byte b[] = new byte[(int)file.length()];
        fin.read(b);

        File nf = new File("D:/K.mp4");
        FileOutputStream fw = new FileOutputStream(nf);
        fw.write(b);
        fw.flush();
        fw.close();

    }

}

```