gpt4 book ai didi

java - 如何将两个 AFP 文件连接在一起

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:36:09 35 4
gpt4 key购买 nike

我有两个 AFP文件,我想将它们连接在一起,我该如何完成。我已经编写了 java 代码来连接它们,使用 BufferedInputStream 和 BufferedOutputStream 结果 AFP 格式不正确。我什至尝试使用 linux cat 但产生了相同的错误结果。请帮忙。我不认为问题出在我的 Java 代码上,但我在下面发布了代码以防万一。

注意:一件奇怪的事情是,如果我切换串联的顺序,它就会产生正确的格式输出。例如,如果我先连接 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 file 1 resources       AND        AFP file 2 resources
AFP file 1 content AFP file 2 content

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

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

所以解决方案是将所有资源导出到外部文件,然后您可以按如下方式连接

AFP file resources
AFP file 1 content
AFP file 2 content

这将解决问题。

关于java - 如何将两个 AFP 文件连接在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7589075/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com