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 文件


- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01