whyclj
2019-02-18 3bc8f0e10656fa27f8e2a762923428db53beb71e
调整代码
1个文件已修改
35 ■■■■■ 已修改文件
DataBase_Bakeup_SocketClient/src/com/main/HzipSocket.java 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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,8 @@
    
    
    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");
    }
}