使用Java Files.copy复制后,出现空白页面的PDF文件 [英] PDF file with empty pages appearing after Copying using Java Files.copy
问题描述
我正在尝试将我的班级路径中的文件复制到另一个临时位置.
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.
干杯, Madhu
推荐答案
问题完全无关.我正在使用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文件上进行的,因此作为空doco复制到了目标文件夹.
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文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!