50分求购java写的具有ftp压缩上传.下载解压功能的代码 急需java写的具有ftp压缩上传.下载解压功能的代码,我的要求是可以把.pdf文档压缩成.zip文件然后上传,也可以下载解压!可否把思路也讲一下,我在网上查的,怎么有的人写的程序继承的是applet,有的人继承的HttpServlet,有的人还分客户端类和服务器类,我都糊涂了!我是不是先要在一台机器上建一个ftp服务器,我的机器充当客户端,是要先搭建好环境吗?急啊!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 问题点数太少了。源代码就不提供了。提供一下大体思路。(WEB系,JSP+SERVLET实现)环境:TOMCAT,IIS的FTP服务先搭建好IIS的FTP服务(也可以使用其他的FTP服务软件)接着就是写一个连接FTP服务器的代码,提供login,get,put,logout等等方法。分别用于登陆FTP服务器,从FTP服务器获得指定的文件,将文件上传到FTP服务器,logout。在写一个用于zip文件操作的代码,提供makeZip,unPack方法,分别用于压缩和解压缩。准备工作做好之后,就是写一个组合上述各个方法的事务Servlet之类的东西了。步骤如下:1)将指定的文件利用makeZip方法,进行压缩2)login FTP服务器3)将1)中压缩的文件,利用put方法,上载到FTP服务器4)logout FTP服务器下载过程一样。其他的自己补充。 可以不用servlet实现吗?我觉得用servlet很麻烦啊!你看我这样写如何://连接ftp服务器 ftp ft = new ftp(); ft.connect(RWFileDir,hostname,port,uid,pwd); public FtpClient connect(String RWFileDir,String hostname,int port,String uid,String pwd) { this.hostname = hostname; System.out.println("正在连接"+hostname+",请等待....."); try{ aftp = new FtpClient(hostname,port); aftp.login(uid,pwd); aftp.binary(); //aftp.openPortDataConnection(); a = "连接主机:"+hostname+"成功!"; System.out.println(a); } catch(FtpLoginException e){ a="登陆主机:"+hostname+"失败!请检查用户名或密码是否正确:"+e; System.out.println(a); //return false; } catch (IOException e){ a="连接主机:"+hostname+"失败!请检查端口是否正确:"+e; System.out.println(a); //return false; } catch(SecurityException e) { a="无权限与主机:"+hostname+"连接!请检查是否有访问权限:"+e; System.out.println(a); //return false; } log(RWFileDir,a); return aftp; } //下载文件public boolean downloadFile(String RWFileDir,String filepathname){ FtpClient fc=new FtpClient(ftp.xx.com); fc.login(username,888888); int ch; File fi = new File(c:\\index.html); RandomAccessFile getFile = new RandomAccessFile(fi,rw); getFile.seek(0); TelnetInputStream fget=fc.get(index.html); DataInputStream puts = new DataInputStream(fget); while ((ch = puts.read()) >= 0) { getFile.write(ch); } fget.close(); getFile.close(); fc.closeServer(); } catch (IOException ex) { ex.printStackTrace(); }大哥我加分好不好!能把代码给我吗?我急用啊!我在加100分给你啊! 总共有几种实现方法啊?我做的是管理模块中的一项,我觉得不适合做成web方式,做成java代码的好些 我经过认真思考把 FTP 服务用映射网络驱动器的方式代替了!思路如下:1.将指定的文件(如 e:\books)用 makezip()方法进行压缩(如压缩为 books.zip);2.将books.zip存放到 w:\ (w为我映射的网络驱动器地址, 它对应与网络上一台计算机的一个文件夹 如 192.168.0.1\ d\share)(相当于上传)3.从 w:\ 上取文件(相当于下载)到指定目录4.将取到的文件用 uppack()方法进行解压我现在就是不知道怎么样写解压和压缩的 java 代码,望大家能够帮下我 我自己写了个解压的程序,不过它报错,大家看看是怎么回事?package com.javaftp;import java.io.*;import java.util.zip.*;public class UnZip { static final int BUFFER = 2048; public static void main(String[] args) { try { BufferedOutputStream dest = null;//打开ZIP输入流 FileInputStream fis = new FileInputStream("e:/XML_exa.zip"); ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis)); ZipEntry entry;//使用getNextEntry方法来读取ZIP文件中的条目数,该方法返回一个ZipEntry对象(zip文件条目)。//如果到达文件的尾部,getNextEntry返回null: while((entry = zis.getNextEntry()) != null) { System.out.println("Extracting: " +entry); int count; byte data[] = new byte[BUFFER];// write the files to the disk//建立输出流 FileOutputStream fos = new FileOutputStream(entry.getName()); dest = new BufferedOutputStream(fos, BUFFER); while ((count = zis.read(data, 0, BUFFER)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); } zis.close(); } catch(Exception e) { e.printStackTrace(); }} }报错Extracting: XML_exa/XML_exa/java.io.FileNotFoundException: XML_exa\XML_exa (系统找不到指定的路径。) at java.io.FileOutputStream.open(Native Method) at java.io.FileOutputStream.<init>(FileOutputStream.java:179) at java.io.FileOutputStream.<init>(FileOutputStream.java:70) at com.javaftp.UnZip.main(UnZip.java:37)是不是我解压的目录没写?怎么写呢??急死我了! apple机如何在dock上建快捷方式 eclipse的控制台不见~郁闷 初学者的问题 --怎样发布SWT应用程序?--急! 关于轮询的问题,哪位高人能详细解释一下? [求助]如何在java中把一个程序做成一个服务 关于I/O的一些疑惑: 小问题~高手来~~ 两个小问题100分,多谢各位! 如何给String加回车,既给一个string赋多行值,立刻给分 我想用APPLET 读取服务器端文件绘制饼图,读不到数据怎么办?急!快帮帮我吧! 怎么回事?修改,重新编译applet后,用ie加载。打开的还是原来的applet。
提供一下大体思路。(WEB系,JSP+SERVLET实现)
环境:TOMCAT,IIS的FTP服务
先搭建好IIS的FTP服务(也可以使用其他的FTP服务软件)接着就是写一个连接FTP服务器的代码,提供login,get,put,logout等等方法。分别用于登陆FTP服务器,从FTP服务器获得指定的文件,将文件上传到FTP服务器,logout。在写一个用于zip文件操作的代码,提供makeZip,unPack方法,分别用于压缩和解压缩。准备工作做好之后,就是写一个组合上述各个方法的事务Servlet之类的东西了。
步骤如下:
1)将指定的文件利用makeZip方法,进行压缩
2)login FTP服务器
3)将1)中压缩的文件,利用put方法,上载到FTP服务器
4)logout FTP服务器下载过程一样。
其他的自己补充。
//连接ftp服务器
ftp ft = new ftp();
ft.connect(RWFileDir,hostname,port,uid,pwd);
public FtpClient connect(String RWFileDir,String hostname,int port,String uid,String pwd)
{
this.hostname = hostname;
System.out.println("正在连接"+hostname+",请等待.....");
try{
aftp = new FtpClient(hostname,port);
aftp.login(uid,pwd);
aftp.binary();
//aftp.openPortDataConnection();
a = "连接主机:"+hostname+"成功!";
System.out.println(a);
}
catch(FtpLoginException e){
a="登陆主机:"+hostname+"失败!请检查用户名或密码是否正确:"+e;
System.out.println(a);
//return false;
}
catch (IOException e){
a="连接主机:"+hostname+"失败!请检查端口是否正确:"+e;
System.out.println(a);
//return false;
}
catch(SecurityException e)
{
a="无权限与主机:"+hostname+"连接!请检查是否有访问权限:"+e;
System.out.println(a);
//return false;
}
log(RWFileDir,a);
return aftp;
}
//下载文件
public boolean downloadFile(String RWFileDir,String filepathname){
FtpClient fc=new FtpClient(ftp.xx.com);
fc.login(username,888888);
int ch;
File fi = new File(c:\\index.html);
RandomAccessFile getFile = new RandomAccessFile(fi,rw);
getFile.seek(0);
TelnetInputStream fget=fc.get(index.html);
DataInputStream puts = new DataInputStream(fget);
while ((ch = puts.read()) >= 0) {
getFile.write(ch);
}
fget.close();
getFile.close();
fc.closeServer();
} catch (IOException ex) { ex.printStackTrace();
}大哥我加分好不好!能把代码给我吗?我急用啊!我在加100分给你啊!
1.将指定的文件(如 e:\books)用 makezip()方法进行压缩(如压缩为 books.zip);
2.将books.zip存放到 w:\ (w为我映射的网络驱动器地址, 它对应与网络上一台计算机的一个文件夹 如 192.168.0.1\ d\share)(相当于上传)
3.从 w:\ 上取文件(相当于下载)到指定目录
4.将取到的文件用 uppack()方法进行解压
我现在就是不知道怎么样写解压和压缩的 java 代码,望大家能够帮下我
package com.javaftp;
import java.io.*;
import java.util.zip.*;
public class UnZip { static final int BUFFER = 2048;
public static void main(String[] args) {
try { BufferedOutputStream dest = null;
//打开ZIP输入流
FileInputStream fis = new FileInputStream("e:/XML_exa.zip"); ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis)); ZipEntry entry;
//使用getNextEntry方法来读取ZIP文件中的条目数,该方法返回一个ZipEntry对象(zip文件条目)。
//如果到达文件的尾部,getNextEntry返回null:
while((entry = zis.getNextEntry()) != null) { System.out.println("Extracting: " +entry); int count; byte data[] = new byte[BUFFER];// write the files to the disk
//建立输出流
FileOutputStream fos = new FileOutputStream(entry.getName()); dest = new BufferedOutputStream(fos, BUFFER); while ((count = zis.read(data, 0, BUFFER)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); } zis.close(); } catch(Exception e) { e.printStackTrace(); }} }报错
Extracting: XML_exa/XML_exa/
java.io.FileNotFoundException: XML_exa\XML_exa (系统找不到指定的路径。)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
at java.io.FileOutputStream.<init>(FileOutputStream.java:70)
at com.javaftp.UnZip.main(UnZip.java:37)是不是我解压的目录没写?怎么写呢??急死我了!