java 中如何打包一个文件为zip 听说rar是收费的。所以打包为zip 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.io.*;import java.util.zip.*;class Zip { public static void main(String args[]) throws IOException { byte b[] = new byte[512]; ZipOutputStream zout = new ZipOutputStream(System.out); for(int i = 0; i < args.length; i ++) { InputStream in = new FileInputStream(args[i]); ZipEntry e = new ZipEntry(args[i].replace(File.separatorChar,'/')); zout.putNextEntry(e); int len=0; while((len=in.read(b)) != -1) { zout.write(b,0,len); } zout.closeEntry(); print(e); } zout.close(); } public static void print(ZipEntry e){ PrintStream err = System.err; err.print("added " + e.getName()); if (e.getMethod() == ZipEntry.DEFLATED) { long size = e.getSize(); if (size > 0) { long csize = e.getCompressedSize(); long ratio = ((size-csize)*100) / size; err.println(" (deflated " + ratio + "%)"); } else { err.println(" (deflated 0%)"); } } else { err.println(" (stored 0%)"); } }}可能会遇到中文乱码问题 打个jar包不就得了。放手机上都嫩用 谁帮我看下这个java计算机的Frame怎么显示不出来啊 从数据库读取到的字段怎么输出 hibernate 查询问题 null怎么表示。 谢谢!! 一个关与LookAndFeel的问题,请帮帮我 如何取得鼠标当前在屏幕中的位置? 初学者的问题 请教,请教,,,一定要看!!一定要看!! 安装完jdk后怎样测试是否配置正确? 怎样得到Graphics类的对象来画图,用什么样的子类 java 的图形设计插件装上了为什么不显示 SCJP 6.0認證教戰手冊考題---34.has-a,is-a疑问
import java.io.*;
import java.util.zip.*;
class Zip {
public static void main(String args[]) throws IOException {
byte b[] = new byte[512];
ZipOutputStream zout = new ZipOutputStream(System.out);
for(int i = 0; i < args.length; i ++) {
InputStream in = new FileInputStream(args[i]);
ZipEntry e = new ZipEntry(args[i].replace(File.separatorChar,'/'));
zout.putNextEntry(e);
int len=0;
while((len=in.read(b)) != -1) {
zout.write(b,0,len);
}
zout.closeEntry();
print(e);
}
zout.close();
} public static void print(ZipEntry e){
PrintStream err = System.err;
err.print("added " + e.getName());
if (e.getMethod() == ZipEntry.DEFLATED) {
long size = e.getSize();
if (size > 0) {
long csize = e.getCompressedSize();
long ratio = ((size-csize)*100) / size;
err.println(" (deflated " + ratio + "%)");
}
else {
err.println(" (deflated 0%)");
}
}
else {
err.println(" (stored 0%)");
}
}
}
可能会遇到中文乱码问题