PDF file with empty pages appearing after Copying using Java Files.copy(使用 Java Files.copy 复制后出现空白页的 PDF 文件)
问题描述
我正在尝试将我的类路径中的文件复制到另一个临时位置.
I am trying to copy a file in my Class path to another temp location.
这是它的代码:
InputStream inputStream = this.getClass().getClassLoader()
.getResourceAsStream(readmeFile);
Path path = Paths.get(tempFilesOutputPath + File.separator + readmeFile);
try {
Files.copy(inputStream, path, StandardCopyOption.REPLACE_EXISTING);
inputStream.close();
} catch (IOException e) {
throw e;
}
readMeFile 有 2 页,tempFilesOutputPath 文件夹中的复制文件也有 2 页,但没有任何内容.
readMeFile has 2 pages, the copied file in the tempFilesOutputPath folder also has two pages but without any content.
如果我犯了一些错误或者必须以不同的方式完成,请告诉我.
Please let me know if I am making some mistake or it has to be done in a different way.
干杯,马杜
推荐答案
问题完全不相关.我正在使用maven复制资源来复制我的src/main/resources/下的资源
Issue was totally unrelated. I was using maven copy resource to copy the resources under my src/main/resources/
这是我的 Maven 资源:
this was my maven resource:
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.txt</include>
<include>**/*.html</include>
<include>**/*.pdf</include>
</includes>
</resource>
由于过滤是针对 PDF 文件,因此被作为空文档复制到目标文件夹.
Since the filtering was on PDF file was copied as an empty doco to the target folder.
我只是将它分成两个资源,过滤掉 PDF 文件.
I just seperated it into two resources with filtering off for PDF file.
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.txt</include>
<include>**/*.html</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>**/*.pdf</include>
</includes>
</resource>
感谢 Drew Buckley,我在尝试对文件进行二进制比较时遇到了问题.项目上的实际文件不同,从 maven 复制的目标文件夹中的文件也不同.
Thanks to Drew Buckley, I got the issue when trying to do a binary comparison of the file. Actual file on the project was different and the one on the target folder which gets copied from the maven was different.
现在可以正常使用了.
这篇关于使用 Java Files.copy 复制后出现空白页的 PDF 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 Java Files.copy 复制后出现空白页的 PDF 文件


基础教程推荐
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 降序排序:Java Map 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01