请教如何对字节流而不是文件进行压缩? 本人对此比较陌生.麻烦指导一下对byte[]的数据怎么进行用java.util.zip的类进行压缩,而不用转换为文件.以及如何将得到的数据再转换为正常的byte[].谢谢各位指点!希望能有详细的代码指导,而不是告诉我怎么样怎么样.多谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 以下就是从fileIn 中读取字节流,再压缩的。private static void zipAFile(File f, ZipOutputStream out, String base) throws Exception { FileInputStream fileIn = new FileInputStream(f); String entryName = f.getPath().substring(base==null?0:base.length()+1); ZipEntry entry = new ZipEntry(entryName); entry.setTime(f.lastModified()); out.putNextEntry(entry); int b = 0; byte[] buffer = new byte[1024]; while ((b=fileIn.read(buffer)) != -1){ out.write(buffer,0,b); } out.closeEntry(); fileIn.close(); } java sql中的游标问题,rs.previous总是报错,statement语句已经设好了,求救 [求教]如何去掉String型变量的全角空格 初学java遇到的问题 java 继承 instanceof 问题 java程序改错 JAVA群 怎样用java抽取html的链接和链接的文本,谢谢 Exception in thread "main" java.lang.NoClassDefFoundError: a 在线等 请问,一个数是否被另一个数整除,怎么做? Applet是否还有用途? 如何在java中调用某类文件的系统编辑器(windows)? 请教一个pattern的写法。
private static void zipAFile(File f, ZipOutputStream out, String base) throws Exception {
FileInputStream fileIn = new FileInputStream(f);
String entryName = f.getPath().substring(base==null?0:base.length()+1);
ZipEntry entry = new ZipEntry(entryName);
entry.setTime(f.lastModified());
out.putNextEntry(entry);
int b = 0;
byte[] buffer = new byte[1024];
while ((b=fileIn.read(buffer)) != -1){
out.write(buffer,0,b);
}
out.closeEntry();
fileIn.close();
}