Administrator
2021-01-22 a40e82e726ae3b5838f7df2a04b8e5db6c38bb7e
DataBase_Bakeup_SocketClient/src/com/main/HzipSocket.java
@@ -8,7 +8,24 @@
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。
   /**
@@ -55,6 +72,7 @@
            zos.flush();
            zos.closeEntry();
         } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
         }
      }
@@ -64,19 +82,10 @@
   
   
   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");
   }
}