| | |
| | | import java.util.zip.ZipEntry;
|
| | | import java.util.zip.ZipOutputStream;
|
| | |
|
| | | public class HzipSocket extends Thread {
|
| | | public class HzipSocket{
|
| | | public static String targetip = "127.0.0.1"; //目标ip地址
|
| | | public static int targetport = 10100; //目标端口号
|
| | | |
| | | public void init(String filepath) {
|
| | | try {
|
| | | Socket s = new Socket("127.0.0.1",10100);
|
| | | //要发送出去的文件夹.请注意在不同操作系统上,表示方法可能不一样。
|
| | | File file =new File(filepath);
|
| | | OutputStream os=s.getOutputStream();
|
| | | ZipOutputStream gout=new ZipOutputStream(os);
|
| | | byte[] b=new byte[1024];
|
| | | zipEntry(file, gout,b);
|
| | | s.close();
|
| | | } catch (IOException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | //无论文件,还是文件夹都是一个ZipEntry。
|
| | | /**
|
| | |
| | | zos.flush();
|
| | | zos.closeEntry();
|
| | | } catch (IOException e) {
|
| | | // TODO Auto-generated catch block
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
| | |
|
| | |
|
| | | public static void main(String[] args) {
|
| | | try {
|
| | | Socket s = new Socket("127.0.0.1",10100);
|
| | | HzipSocket h = new HzipSocket();
|
| | | //要发送出去的文件夹.请注意在不同操作系统上,表示方法可能不一样。
|
| | | File file =new File("D:/temp");
|
| | | OutputStream os=s.getOutputStream();
|
| | | ZipOutputStream gout=new ZipOutputStream(os);
|
| | | byte[] b=new byte[1024];
|
| | | h.zipEntry(file, gout,b);
|
| | | s.close();
|
| | | } catch (IOException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | HzipSocket h = new HzipSocket();
|
| | | h.init("d:/temp");
|
| | | }
|
| | | }
|
| | |
|