项目差异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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Jenkins(4)docker容器内部修改jenkins容器时间「建议收藏」

    Jenkins(4)docker容器内部修改jenkins容器时间「建议收藏」前言用docker搭建的Jenkins环境时间显示和我们本地时间相差8个小时,需修改容器内部的系统时间查看时间查看系统时间date-R进入docker容器内部,查看容器时间dockere

    2022年7月28日
    6
  • java重构方式

    java重构方式这里只是简单例子,以动物方式,如何实现重构1、入口publicclassTestMain{@AutowiredprivateAnimalanimal;@Testpublicvo

    2022年7月2日
    21
  • navacat15 激活码【在线注册码/序列号/破解码】

    navacat15 激活码【在线注册码/序列号/破解码】,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月18日
    53
  • blender2.9教程_赖世雄入门篇

    blender2.9教程_赖世雄入门篇Blender2.8基础(一)基础操作与常用快捷键▶Ctrl+N:创建新工程一、视图操作1、放大视图▶视图最大化显示:Ctrl+空格(左键点击视图任意地方可以选择视图,然后按Ctrl+空格可以最大化显示视图。)▶切换全屏模式:Ctrl+Alt+空格2、切换视图▶切换视图:Alt(按住不放)+按住中键上下或左右移动鼠标(每切换一次视图就必须重新按一下中键并移动鼠标)▶……

    2022年8月10日
    7
  • http 415 错误

    http 415 错误惯例:我是温浩然:http错误,415,以前没有遇到过,遇到的都是404,500什么的,今天遇到了415错误,找了其他人的,发现说的也不明白。我这里说一下吧,发生415错误的原因。你想要请求一个方法,这个方法需要传map类型的参数(哪怕是空的呢),你什么都没有传入,就报错415.

    2022年6月11日
    35
  • oracle里面concat函数用法,oracle wm_concat函数用法-Oracle

    oracle里面concat函数用法,oracle wm_concat函数用法-Oraclewmsys.wm_concat函数,它的作用是以’,’链接字符例子如下:SQL>createtableidtable(idnumber,namevarchar2(30));TablecreatedSQL>insertintoidtablevalues(10,’ab’);1rowinsertedSQL>insertintoidtablevalues…

    2022年5月18日
    51

发表回复

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

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