zoukankan      html  css  js  c++  java
  • 项目差异class文件提取-->上线用

    package fileReader;
    
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStream;
    
    import javax.swing.JOptionPane;
    
    public class DemoFilre {
        private static String MESSAGE = "";
    
        public static void main(String[] args) {
            String filePath = System.getProperty("user.home") + "\Desktop\aaa.txt";
            readTxtFile(filePath);
    
        }
    
        public static void readTxtFile(String filePath) {
            try {
                String encoding = "GBK";
                File file = new File(filePath);
                if (file.isFile() && file.exists()) { // 判断文件是否存在
                    InputStreamReader read = new InputStreamReader(
                            new FileInputStream(file), encoding);// 考虑到编码格式
                    BufferedReader bufferedReader = new BufferedReader(read);
                    String lineTxt = null;
                    while ((lineTxt = bufferedReader.readLine()) != null) {
                        if(lineTxt.startsWith("==")) continue;
                        if(lineTxt.isEmpty()) continue;
                        System.out.println("D:\workspace\spdbSjptServer\WebRoot\" + lineTxt.toString());
                        // 读文件,copy
                        copyFile("D:\workspace\spdbSjptServer\WebRoot\" + lineTxt.toString(), System.getProperty("user.home") + "\Desktop\待上线\" + lineTxt.toString(), true);
                    }
                    read.close();
                } else {
                    System.out.println("找不到指定的文件");
                }
            } catch (Exception e) {
                System.out.println("读取文件内容出错");
                e.printStackTrace();
            }
    
        }
    
        public static boolean copyFile(String srcFileName, String destFileName,
                boolean overlay) {
            File srcFile = new File(srcFileName);
    
            // 判断源文件是否存在
            if (!srcFile.exists()) {
                MESSAGE = "源文件:" + srcFileName + "不存在!";
                JOptionPane.showMessageDialog(null, MESSAGE);
                return false;
            } else if (!srcFile.isFile()) {
                MESSAGE = "复制文件失败,源文件:" + srcFileName + "不是一个文件!";
                JOptionPane.showMessageDialog(null, MESSAGE);
                return false;
            }
    
            // 判断目标文件是否存在
            File destFile = new File(destFileName);
            if (destFile.exists()) {
                // 如果目标文件存在并允许覆盖
                if (overlay) {
                    // 删除已经存在的目标文件,无论目标文件是目录还是单个文件
                    new File(destFileName).delete();
                }
            } else {
                // 如果目标文件所在目录不存在,则创建目录
                if (!destFile.getParentFile().exists()) {
                    // 目标文件所在目录不存在
                    if (!destFile.getParentFile().mkdirs()) {
                        // 复制文件失败:创建目标文件所在目录失败
                        return false;
                    }
                }
            }
    
            // 复制文件
            int byteread = 0; // 读取的字节数
            InputStream in = null;
            OutputStream out = null;
    
            try {
                in = new FileInputStream(srcFile);
                out = new FileOutputStream(destFile);
                byte[] buffer = new byte[1024];
    
                while ((byteread = in.read(buffer)) != -1) {
                    out.write(buffer, 0, byteread);
                }
                return true;
            } catch (FileNotFoundException e) {
                return false;
            } catch (IOException e) {
                return false;
            } finally {
                try {
                    if (out != null)
                        out.close();
                    if (in != null)
                        in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
  • 相关阅读:
    Compression algorithm (deflate)
    tcpip数据包编码解析(chunk and gzip)_space of Jialy_百度空间
    What's the difference between the "gzip" and "deflate" HTTP 1.1 encodings?
    gzip压缩算法: gzip 所使用压缩算法的基本原理
    Decompressing a GZip Stream with Zlib
    Frequently Asked Questions about zlib
    how to decompress gzip stream with zlib
    自己动手写web服务器四(web服务器是如何通过压缩数据,web服务器的gzip模块的实现)
    What's the difference between the "gzip" and "deflate" HTTP 1.1 encodings?
    C语言抓http gzip包并解压 失败 C/C++ ChinaUnix.net
  • 原文地址:https://www.cnblogs.com/sprinng/p/5841697.html
Copyright © 2011-2022 走看看