【发布时间】:2015-11-01 21:25:14
【问题描述】:
我编写了一个 JAVA 源代码来压缩 Oracle DB 11g 中的文件。该程序按预期工作,即它正在 /home/oracle/ 目录中创建 zip 文件。但是当我通过 FTP 将文件下载到我的硬盘或使用 SMTP 服务器通过电子邮件发送它们时,7Zip 拒绝读取存档的内容并抛出错误:-
“DAR.xls 不支持的压缩方法”
我在这里做错了吗?请帮忙。
附上JAVA源码的代码:
CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "UTLZip" AS
import java.util.zip.*;
import java.io.*;
public class UTLZip
{
public static void compressFile(String infilename, String outfilename)
{
String zipFile = "/home/oracle/DAR.zip";
String[] srcFiles = {"/home/oracle/DAR.xls"};
try {
// create byte buffer
byte[] buffer = new byte[1024];
FileOutputStream fos = new FileOutputStream(zipFile);
ZipOutputStream zos = new ZipOutputStream(fos);
for (int i=0; i < srcFiles.length; i++) {
File srcFile = new File(srcFiles[i]);
FileInputStream fis = new FileInputStream(srcFile);
zos.putNextEntry(new ZipEntry(srcFile.getName()));
int length;
while ((length = fis.read(buffer)) > 0) {
zos.write(buffer, 0, length);
}
zos.closeEntry();
// close the InputStream
fis.close();
}
// close the ZipOutputStream
zos.close();
}
catch (IOException ioe) {
System.out.println("Error creating zip file: " + ioe);
}
}
}
【问题讨论】:
-
你确定你刚刚写的文件不用下载就可以解压吗?您应该能够在您的 PC 上运行和测试它>
标签: java file oracle11g compression 7zip