文本对比器

工作遇到oracle数据库迁移到MySQL数据库,用到校验缺失表

表太多随便搞了个文本对比器做下记录

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class TextComparatorIgnoreCase {
    public static void main(String[] args) {
//        文件1中缺失而文件2中存在的内容
        String file1Path = "C:\\Users\\Administrator\\Desktop\\file1.txt";
        String file2Path = "C:\\Users\\Administrator\\Desktop\\file2.txt";

        try {
            String file1Content = getFileContent(file1Path);
            String file2Content = getFileContent(file2Path);

            compareTextIgnoreCase(file1Content, file2Content);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static String getFileContent(String filePath) throws IOException {
        StringBuilder content = new StringBuilder();
        BufferedReader reader = new BufferedReader(new FileReader(filePath));
        String line;
        while ((line = reader.readLine()) != null) {
            content.append(line).append("\n");
        }
        reader.close();
        return content.toString();
    }

    private static void compareTextIgnoreCase(String text1, String text2) {
        String[] lines1 = text1.split("\n");
        String[] lines2 = text2.split("\n");

        System.out.println("文件1中缺失的内容:");
        for (String line2 : lines2) {
            boolean found = false;
            for (String line1 : lines1) {
                if (line1.equalsIgnoreCase(line2)) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                System.out.println(line2);
            }
        }
    }
}
import java.io.*;

public class TextToLowercase {
    public static void main(String[] args) {
        String filePath = "C:\\Users\\Administrator\\Desktop\\input.txt";
        String outputFilePath = "output.txt";

        try {
            String fileContent = getFileContent(filePath);
            String lowercaseContent = fileContent.toLowerCase();
            writeToFile(outputFilePath, lowercaseContent);
            System.out.println("文本内容已成功转换为小写并保存到文件 " + outputFilePath);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static String getFileContent(String filePath) throws IOException {
        StringBuilder content = new StringBuilder();
        BufferedReader reader = new BufferedReader(new FileReader(filePath));
        String line;
        while ((line = reader.readLine()) != null) {
            content.append(line).append("\n");
        }
        reader.close();
        return content.toString();
    }

    private static void writeToFile(String filePath, String content) throws IOException {
        BufferedWriter writer = new BufferedWriter(new FileWriter(filePath));
        writer.write(content);
        writer.close();
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值