首页 > 解决方案 > 用Java读取后二进制文件的大小变化

问题描述

我的应用程序工作区上有一个大小为 512 字节的 jceks(密钥库文件)。我有下面的 java 代码,它读取这个二进制 jceks 文件并使用 Feign Client 将其推送到 Bitbucket。当文件被推送到 Bitbucket 时,大小变为 696 字节(使用 UTF-8 编码,甚至在下面的第 3 步中没有编码)。当我尝试在下面的步骤 3 中使用其他编码(如 UTF-16、UTF-16LE、UTF-BE、US-ASCII、ISO-8859_1)时,根据编码,推送文件的大小变为 707 字节、721 字节等. 有人可以让我知道如何解决这个问题吗?

//Imports
import java.nio.charset.StandardCharsets;

import java.nio.file.Files;

import java.nio.file.Paths;

//Steps

1.File f = new File(//Path of jceks file on my application workspace);

2.byte[] encoded = Files.readAllBytes(Paths.get(f.getPath));

3.String toSave = new String(encoded, StandardCharsets.UTF-8);

//This String 'toSave' is what i pass to Bitbucket API which     pushes the jceks file to Bitbucket, but the size in different from actual jceks file.

标签: java

解决方案


推荐阅读