惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
Stack Overflow Blog
Stack Overflow Blog
人人都是产品经理
人人都是产品经理
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
Vercel News
Vercel News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Y
Y Combinator Blog
The Cloudflare Blog
Last Week in AI
Last Week in AI
B
Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog
V
Visual Studio Blog
博客园 - 三生石上(FineUI控件)
小众软件
小众软件
Google DeepMind News
Google DeepMind News
D
DataBreaches.Net
博客园 - 司徒正美
B
Blog RSS Feed
Microsoft Azure Blog
Microsoft Azure Blog
罗磊的独立博客
Hugging Face - Blog
Hugging Face - Blog
L
LangChain Blog

博客园 - _万古如长夜

WEB项目引入druid监控配置 java log4j 代码中 新增按日保存日志文件的功能 按钮居中固定 博文阅读密码验证 - 博客园 tomcat-设置jdk-设置标题-设置内存-配置项目路径 博文阅读密码验证 - 博客园 博文阅读密码验证 - 博客园 博文阅读密码验证 - 博客园 qrtz表初始化脚本_mysql 工具类 从jar包里复制要打生产的补丁(仅限T2) CPU使用过高问题/死锁 tomcat jvm 内存配置 文件下载-文件后缀 匹配content-type wsdl调用 不生成java文件方式 工具类-老版hibernate 占位符模式(?) in 的问题解决方案 nginx 设置超时 常用的正则表达式 DB2各种命令 mysql 各种命令
解析文件内容,匹配请求路径
_万古如长夜 · 2026-04-08 · via 博客园 - _万古如长夜
package com.bytter.ext.test;

import jxl.Workbook;
import jxl.WorkbookSettings;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

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

public class TestYidong {

    public static void main(String[] args) throws Exception{
        try {
            // 指定Excel文件路径
            String filePath = "C:\\Users\\zuiai\\Desktop\\example.xls";
            File file = new File(filePath);

            // 创建WorkbookSettings对象,可以设置编码等属性
            WorkbookSettings wbSettings = new WorkbookSettings();
            // 创建WritableWorkbook对象,用于写入数据
            WritableWorkbook workbook = Workbook.createWorkbook(file, wbSettings);
            workbook.createSheet("Sheet1", 0); // 创建工作表Sheet1
            WritableSheet sheet = workbook.getSheet(0); // 获取第一张工作表


            File folder = new File("E:\\software\\workspace\\ysjh_yunnan\\tdesignsign-dev");
            String keyword = "/api/audit/ysjh";
            File[] listOfFiles = folder.listFiles();
            int index = 0;
            // 写入数据到第一列和第二列,从第1行开始(Excel中第1行实际上是第0行)
            Label label1 = new Label(0, index, "文件路径"); // 第1列第1行(0-based index)
            Label label2 = new Label(1, index, "请求路径"); // 第2列第1行(0-based index)
            sheet.addCell(label1); // 添加到工作表
            sheet.addCell(label2); // 添加到工作表
            index++;

            outs(listOfFiles,keyword,sheet,index);

            // 写入完成后,关闭workbook以保存数据到文件
            workbook.write();
            workbook.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    private static void outs(File[] listOfFiles, String keyword, WritableSheet sheet, int index) throws Exception{

        if (listOfFiles != null) {
            for (File file : listOfFiles) {
                if (file.isFile()) { // 确保是文件
                    if(file.getName().endsWith(".js")){
                        System.out.println("File: " + file.getAbsolutePath());

                        try (BufferedReader br = new BufferedReader(new FileReader(file))) {
                            String line;
                            while ((line = br.readLine()) != null) {
                                if (line.contains(keyword)) {
                                    // 写入数据到第一列和第二列,从第1行开始(Excel中第1行实际上是第0行)
                                    Label label1 = new Label(0, index, file.getAbsolutePath()); // 第1列第1行(0-based index)
                                    Label label2 = new Label(1, index, line); // 第2列第1行(0-based index)
                                    sheet.addCell(label1); // 添加到工作表
                                    sheet.addCell(label2); // 添加到工作表
                                    index++;
                                }
                            }
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }else{
                    outs(file.listFiles(),keyword,sheet,index);
                }
            }
        }
    }
}