项目差异class文件提取–>上线用

项目差异class文件提取–>上线用packagefileReader;importjava.io.BufferedReader;importjava.io.File;importjava.io.FileInputStre

大家好,又见面了,我是你们的朋友全栈君。

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();
            }
        }
    }
}

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/154306.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 微信小程序 40029错误

    微信小程序 40029错误{“errmsg”:“invalidcode,hints:[req_id:xxxxxxx],“errcode”:40029”}查看project.config.json中的appid是否与自己申请的appid一致。不一致就会出现这种问题。解决方法就是改成自己申请的appid…

    2022年4月28日
    45
  • axios 跨域问题_为什么会出现跨域问题

    axios 跨域问题_为什么会出现跨域问题什么是跨域首先需要了解到浏览器的同源策略,同源策略是最核心也是最基本的安全功能,缺少同源策略浏览器的正常功能可能会受到影响。同源策略会阻止一个域的javascript脚本和另外一个域的能容进行交互。同源(即指在同一个域)就是两个页面具有相同的协议(protocol)、主机(host)和端口号(port)。当一个请求url的协议、域名、端口三个之间任意一个与当前页面url不同即为跨域。Vue中用Axios解决跨域问题配置代理可解决使用Axios不能直接进行跨域…

    2022年9月12日
    2
  • 如何创建一个SpringBoot项目?(详细的图文教程)

    如何创建一个SpringBoot项目?(详细的图文教程)SpringBoot简介SpringBoot官网地址:https://www.spring.io官网介绍:SpringBootmakesiteasytocreatestand-alone,production-gradeSpring-basedApplicationsthatyoucanrun.WetakeanopinionatedviewoftheSpringplatformandthird-partylibraries,sothaty

    2022年8月31日
    5
  • 二叉树的先序,中序,后序遍历的序列_二叉树先序遍历和后序遍历正好相反

    二叉树的先序,中序,后序遍历的序列_二叉树先序遍历和后序遍历正好相反    二叉树的遍历主要有三种:(1)先(根)序遍历(根左右)(2)中(根)序遍历(左根右)(3)后(根)序遍历(左右根)举个例子:先(根)序遍历(根左右):ABDHEICFJKG中(根)序遍历(左根右):DHBEIAJFKCG后(根)序遍历(左右根):HDIEBJKFGCA    以后(根)序…

    2022年9月14日
    2
  • FileZilla出现Failed to convert command to 8 bit charset 

    FileZilla出现Failed to convert command to 8 bit charset 

    2021年9月24日
    49
  • item buffer_addlistener

    item buffer_addlistener当创建DataGrid控件中的项时(不论是在往返行程中还是在将数据绑定到控件时),都会引发ItemCreated事件。ItemCreated事件通常用于控制DataGrid控件中行的内容和外观。当项被数据绑定到DataGrid控件后,将引发ItemDataBound事件。此事件为您提供了在客户端显示数据项之前访问该数据项的最后机会。当引发此事件后,该数据项将被设为空,并且不再

    2022年10月13日
    1

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号