如何将两个AFP文件连接在一起 [英] How do I concatenate two AFP files together

查看:128
本文介绍了如何将两个AFP文件连接在一起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个 AFP 文件,我想将它们串联在一起,如何我能做到这一点吗?我使用BufferedInputStream和BufferedOutputStream编写了将它们连接起来的Java代码,结果AFP格式不正确.我什至尝试使用linux cat,但会产生相同的错误结果.请帮忙.我不认为问题出在我的Java代码上,但是为了以防万一,我在下面发布了代码.

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.

注意:一件奇怪的事情是,如果我切换串联的顺序,那么它将产生正确的格式输出.例如,如果我将A.afp然后B.afp串联,则输出混乱,但是如果我将B.afp串联,则A.afp则产生正确的格式结果.但是我需要A.afp出现在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) {

        }
    }
}

Xenos D2e软件默认在

推荐答案

AFP中生成的AFP在页面顶部包含内联资源,像这样

AFP generated by Xenos D2e software by default contain inline resources at the top of the pages, like this

AFP file 1 resources       AND        AFP file 2 resources
AFP file 1 content                    AFP file 2 content

但是,当我尝试将这两个文件串联在一起时,一些资源将位于串联文件的中间,因此会弄乱结果

However when I try to concatenate these two file together, some resources will be at the middle of the concatenated file, hence mess up the result

AFP file 1 resources
AFP file 1 content
AFP file 2 resources ------> resources should not be in the middle page
AFP file 2 content

所以解决方案是将所有资源导出到一个外部文件,然后可以按如下所示进行串联

so the solution is to export all resources to an external file, then you can concatenated as follow

AFP file resources
AFP file 1 content
AFP file 2 content

这将解决问题.

这篇关于如何将两个AFP文件连接在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆