【发布时间】:2013-07-04 03:35:00
【问题描述】:
我正在尝试将文件 (Base.jar) 复制到与正在运行的 jar 文件相同的目录 我不断得到一个损坏的 jar 文件,当用 winrar 打开时,它仍然保持正确的类结构。我究竟做错了什么? (我也尝试过不使用 ZipInputStream,但这没有帮助)字节 [] 是 20480,因为这是它在磁盘上的大小。
我的代码:
private static void getBaseFile() throws IOException
{
InputStream input = Resource.class.getResourceAsStream("Base.jar");
ZipInputStream zis = new ZipInputStream(input);
byte[] b = new byte[20480];
try {
zis.read(b);
} catch (IOException e) {
}
File dest = new File("Base.jar");
FileOutputStream fos = new FileOutputStream(dest);
fos.write(b);
fos.close();
input.close();
}
【问题讨论】:
-
您是否尝试过逐字节比较文件?如果我不得不猜测,我怀疑您正在从文件末尾修剪字节。
标签: java jar resources stream zip