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


相关推荐

  • 计算机网络ip地址划分范围,ip地址分类及范围划分有哪些

    计算机网络ip地址划分范围,ip地址分类及范围划分有哪些ip地址分为网络地址和主机地址,IP地址是真正网络中计算机的身份标识。手机的IP是手机上网使用的地址,不论是手机还是电脑,一个网段里面只有一个IP,所以每个人手机的IP都是唯一的,当用手机发朋友圈时,就会显示手机ip地址所在地,因此有些人会想要修改手机ip地址。那么ip地址可分为哪几类?其范围是怎么划分的?如何修改手机ip地址?下面小编为大家解答手机ip地址修改方法及ip地址分类及范围划分等知识。…

    2022年5月29日
    50
  • 网页设计音乐播放器_简洁的音乐播放器

    网页设计音乐播放器_简洁的音乐播放器今天闲着无事,就想写点东西。然后听了下歌,就打算写个播放器。于是乎用h5audio的加上js简单的播放器完工了。演示地点演示html代码如下` music 这个年纪 七月的风 音乐 `然后就是css`*{ margin:0; padding:0; text-decoration:none; list-…

    2022年10月13日
    3
  • Groovy新手教程

    Groovy新手教程

    2021年12月1日
    38
  • deepcopy和copy_python中copy和deepcopy的区别

    deepcopy和copy_python中copy和deepcopy的区别Python深浅复制一般对象的复制复杂对象的复制  最近遇到了有关Python中的copy与deepcopy问题,之前再Java里面好像也遇到了深浅复制的问题,但是Python中的深浅复制还不是很熟,就简单了解了一下它们2个的差别,可以供大家参考,不对的地方欢迎大家批评指正。一般对象的复制  针对Python中简单对象的复制,copy和deepcopy…

    2022年10月2日
    2
  • laravel中如何在模型中自关联?

    laravel中如何在模型中自关联?

    2021年11月8日
    38
  • C++使用eigen库做本征分解(eigendecomposition)

    C++使用eigen库做本征分解(eigendecomposition)Eigendecomposition的概念可见https://en.wikipedia.org/wiki/Eigendecomposition_of_a_matrix这里贴一段厄米矩阵的代码,见ht

    2022年8月2日
    4

发表回复

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

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