I have two AFP files and I want to concatenate them together, how can I accomplish this. I have written java code to concatenate them, using BufferedInputStream and BufferedOutputStream and the result AFP is not correctly format. I even try to use linux cat but yield the same incorrect result. Please help. I dont think the problem is my java code, but I post the code below just in case.
NOTE: One strange thing is that if I switch the order of the concatenation then it yield the right format output. For example if I concatenate A.afp then B.afp, then the output is messed up, but if I concatenate B.afp, then A.afp then it yield correct format result. But I need A.afp to appear before B.afp
public static void main(String[] args) {
String filePath1 = "C:\\dev\\harry\\ETCC_data\\3199_FI_20_20110901143009.afp";
String filePath2 = "C:\\dev\\harry\\ETCC_data\\3643_FI_49_20110901143006.afp";
ConcatenateMain cm = new ConcatenateMain();
cm.concate(filePath1, filePath2);
}
private void concate(String filePath1, String filePath2){
BufferedInputStream bis1 = null;
BufferedInputStream bis2 = null;
FileInputStream inputStream1 = null;
FileInputStream inputStream2 = null;
FileOutputStream outputStream = null;
BufferedOutputStream output = null;
try{
inputStream1 = new FileInputStream(filePath1);
inputStream2 = new FileInputStream(filePath2);
bis1 = new BufferedInputStream(inputStream1);
bis2 = new BufferedInputStream(inputStream2);
List<BufferedInputStream> inputStreams = new ArrayList<BufferedInputStream>();
inputStreams.add(bis1);
inputStreams.add(bis2);
outputStream = new FileOutputStream("C:\\dev\\harry\\ETCC_data\\output.afp");
output = new BufferedOutputStream(outputStream);
byte [] buffer = new byte[BUFFER_SIZE];
for(BufferedInputStream input : inputStreams){
try{
int bytesRead = 0;
while ((bytesRead = input.read(buffer, 0, buffer.length)) != -1)
{
output.write(buffer, 0, bytesRead);
}
}finally{
input.close();
}
}
}catch(IOException e){
}finally{
try {
output.close();
} catch (IOException e) {
}
}
}