gpt4 book ai didi

java - 使用 Java 将 BinHex 文件转换为普通文件

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:55:44 25 4
gpt4 key购买 nike

<分区>

我有一个 binhex 文件。应使用 Java 代码将此文件转换为正常的可读文件。我在这里发现了一个类似的问题,

Binhex decoding using java code

但答案不起作用。

我试过 Base64,文件被转换成其他一些人类不可读的格式。

请帮我解决这个问题。

我试过的代码如下

File f = new File("Sample.pdf");
Base64 base64 = new Base64();
byte[] b = base64.decode(getBytesFromFile(f));
FileOutputStream fos = new FileOutputStream("Dcode.pdf");
fos.write(b);
fos.close();

public static byte[] getBytesFromFile(File file) throws IOException {
InputStream is = new FileInputStream(file);
long length = file.length();
byte[] bytes = new byte[(int)length];
int offset = 0;
int numRead = 0;
while (offset < bytes.length && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0)
{
offset += numRead;
}
if (offset < bytes.length) {
throw new IOException("Could not completely read file "+file.getName());
}
is.close();
return bytes;
}

文件 Sample.pdf 是 BinHex 编码的。我希望文件被解码。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com