java文件 内容变成空白,使用Java Files.copy复制后出现空白页面的PDF文件

I am trying to copy a file in my Class path to another temp location.

Here is the code for it:

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 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.

Cheers,

Madhu

解决方案

Issue was totally unrelated. I was using maven copy resource to copy the resources under my src/main/resources/

this was my maven resource:

src/main/resources

true

**/*.properties

**/*.xml

**/*.txt

**/*.html

**/*.pdf

Since the filtering was on PDF file was copied as an empty doco to the target folder.

I just seperated it into two resources with filtering off for PDF file.

src/main/resources

true

**/*.properties

**/*.xml

**/*.txt

**/*.html

src/main/resources

false

**/*.pdf

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.

It works fine now.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值