some questions

bonmot 2003-08-22 03:28:26
1.how to get the compter IP address which the Java precedure is running
2.how to download a file in JSP
3.how to do zipfile in Java
...全文
39 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
bonmot 2003-08-22
  • 打赏
  • 举报
回复
这样吧,我先结了这一贴,另开一贴,希望继续指教
bonmot 2003-08-22
  • 打赏
  • 举报
回复
is there simple way to zip a dir and its recursive files
bonmot 2003-08-22
  • 打赏
  • 举报
回复
download is not that simple,I try:

response.setContentType("application/msexcel");
OutputStream os = response.getOutputStream();
response.setHeader("Content-disposition","attachment; filename=courseware.xls");
os.write(bytes);
os.close();

but can't effect
wizardho 2003-08-22
  • 打赏
  • 举报
回复
ZipFile(File file)
Opens a ZIP file for reading given the specified File object.

ZipFile(File file, int mode)
Opens a new ZipFile to read from the specified File object in the specified mode.

ZipFile(String name)
Opens a zip file for reading.
cricketlj 2003-08-22
  • 打赏
  • 举报
回复
2.download直接连接到你的文件就可以,把你的文件放在webapps的某个目录下面
3.
package com.bj.zk.util.comm;

import java.util.*;
import java.sql.*;
import org.apache.log4j.Logger;
import java.util.zip.*;
import java.io.* ;

//******************************************
/**
*字符串压缩和解压缩

*@author 常通多维CTDW
*@version 2003.07.12
*/
//******************************************

public class ZipAndUnzip{

static Logger logger = Logger.getLogger(ZipAndUnzip.class.getName());

/**
* 字符串压缩
*@param String 被压缩字符串
*@exception exception 例外错误
*/
public void stringZip(String strXml)throws Exception{

byte[] bt;
bt=strXml.getBytes();
//在此路径生成ZIP文件target.zip
FileOutputStream fs = new FileOutputStream("C:/target.zip");

ZipOutputStream zipStream = new ZipOutputStream(fs);
try{
//创建target.zip的tableData.mxl被压缩文件
ZipEntry entry = new ZipEntry("tableData.xml");
//写数据到tableData.mxl
zipStream.putNextEntry(entry);
for(int i=0;i<bt.length/1000;i++){
zipStream.write(bt,i*1000,1000);
}
zipStream.write(bt,(bt.length/1000)*1000,bt.length-(bt.length/1000)*1000);
}catch(Throwable t){logger.info(t.toString());}
zipStream.close();
fs.close();
}

/**
* 字符串解压缩
*@return String 解压缩后字符串
*@exception exception,Throwable 例外错误
*/
public String stringUnzip()throws Exception,Throwable{
String st="";
try{
//被解压缩文件C:/target.zip
ZipFile zf=new ZipFile("C:/target.zip");
Enumeration e=zf.entries();
ZipEntry ze=(ZipEntry)e.nextElement();
//文件大小
int size=0;
size=(int)ze.getSize();
zf.close();

FileInputStream fis=new FileInputStream("C:/target.zip");
ZipInputStream zis=new ZipInputStream(fis);
ZipEntry entry = null;
entry=zis.getNextEntry();
//解成byte[]
byte[] b=new byte[size];
int rb=0;
int chunk=0;
while ((size - rb) > 0) {
chunk=zis.read(b,rb,size - rb);
if (chunk==-1) {
break;
}
rb+=chunk;
}
st=new String(b);
zis.close();
fis.close();

}catch(Throwable t){
logger.info(t.toString());
throw t;
}
return st;
}
}
hayai 2003-08-22
  • 打赏
  • 举报
回复
看看java.util.zip package.
zcjl 2003-08-22
  • 打赏
  • 举报
回复
那就up
:)
neuyqy 2003-08-22
  • 打赏
  • 举报
回复
up!
bonmot 2003-08-22
  • 打赏
  • 举报
回复
thanks,I've got
java.net.InetAddress.getLocalHost().getHostAddress()
nomenn 2003-08-22
  • 打赏
  • 举报
回复
InetAddress 类可以获得IP地址
bonmot 2003-08-22
  • 打赏
  • 举报
回复
up 有分

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧