项目差异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)
上一篇 2022年7月4日 下午3:46
下一篇 2022年7月4日 下午3:46


相关推荐

  • oracle常见sql笔试题,一路SQL笔试题

    oracle常见sql笔试题,一路SQL笔试题SQLcodeSQL gt witht 教师号 星期号 是否有课 as 2select1 2 有 fromdual3uni 3 有 fromdual4uni 1 有 fromdual5uni 2 有 fromdual6uni

    2026年3月20日
    2
  • 卡尔曼滤波(kalman)相关理论以及与HMM、最小二乘法关系

    卡尔曼滤波(kalman)相关理论以及与HMM、最小二乘法关系

    2021年11月19日
    65
  • JS跳转代码_javascript跳转代码

    JS跳转代码_javascript跳转代码<scriptlanguage=”javascript”type=”text/javascript”>functionrequest(paras){varurl=location.href;varparaString=url.substring(url.indexOf(“?”)+1,url.length).split(“&”);varparaObj={}for(i=0;j=paraString[i];i++){paraObj[j.substrin

    2022年8月13日
    12
  • 用html做简单的日记,学习HTML日记[通俗易懂]

    用html做简单的日记,学习HTML日记[通俗易懂]1。html>是什么意思?[1]DOCTYPE标签是一种标准通用标记语言的文档类型声明,它的目的是要告诉标准通用标记语言解析器,它应该使用什么样的文档类型定义(DTD)来解析文档。html5标准网页声明,原先的是一串很长的字符串,现在是这个简洁形式,支持html5标准的主流浏览器都认识这个声明。表示网页采用html52.开始标签结束标签3.这是最外的一层中文编码目前在大部分浏览器中,…

    2022年5月27日
    55
  • unity3d的入门教程_Unity3D缺点

    unity3d的入门教程_Unity3D缺点Unity3D新手入门初级教程U3D是由UnityTechnologies开发的一个让玩家轻松创建诸如三维视频游戏、建筑可视化、实时三维动画等类型互动内容的多平台的综合型游戏开发工具,是一个全面整合的专业游戏引擎。可发布游戏至Windows、Mac、Wii、iPhone、Windowsphone8和Android平台。也可以利用Unitywebplayer插件发布网页游戏,支持Mac和Windows的网页浏览。它的网页播放器也被Macwidgets所支持!U3D现已经占领了国内85%的手游

    2022年8月10日
    7
  • p6使用教程_p6slite

    p6使用教程_p6slite文章目录简介1、Maven依赖2、 切换driverClass(必须)3、增加配置文件4、自定义配置类简介p6spy是一个开源项目,通常使用它来跟踪数据库操作,查看程序运行过程中执行的sql语句。展示效果如下:SQL耗时【7毫秒】连接信息【jdbc:p6spy:mysql://192.168.1.108:3306/leimingtech_member?allowMultiQueries=t…

    2022年10月6日
    5

发表回复

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

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