Hello I have the next code:
package com.jucepho;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
class Copy{
public Copy(byte[] buffer,int count) {
this.buffer = buffer;
this.count = count;
}
private byte[] buffer;
private int count;
public byte[] getBuffer() {
return buffer;
}
public int getCount() {
return count;
}
}
public class ReaderTwo {
public static void main(String[] args) throws IOException {
InputStream is = new FileInputStream("ex.docx");
OutputStream os = new FileOutputStream("exBu.docx");
OutputStream os2 = new FileOutputStream("exBu2.docx");
ArrayList<Copy> lista = new ArrayList<>();
byte[] buffer = new byte[4096];
int count;
while ((count = is.read(buffer)) > 0)
{
os.write(buffer, 0, count);
lista.add(new Copy(buffer,count));
}
for(Copy c: lista) {
os2.write(c.getBuffer(), 0, c.getCount());
}
}
}
I want to read a file more than 5 GB in order to save it. So I saw that I have to read it in this way (Encrypting a large file with AES using JAVA)
My question is, why
OutputStream os = new FileOutputStream("exBu.docx");
copy the data good, i mean the file is correct but
OutputStream os2 = new FileOutputStream("exBu2.docx");
is not correct, is corrupted or I don't know why if I am doing the same, right? I am saving in my ArrayList the same information so why my file is corrupted. (and yeah I need to save all the information in an Object called Copy as you see because I will use serialization and save it in other HD)
Thank you