E文档解析

博客提及开发环境为 Java 8,Java 是后端开发常用语言,Java 8 有诸多特性和优势,在信息技术领域应用广泛。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境java8

import com.google.common.io.Files;

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.stream.Collectors;

/**
 * Created with IntelliJ IDEA.
 * User: zy
 * Date: 2019/5/28
 * Time: 15:51
 * To change this template use File | Settings | File Templates.
 * Description:
 */
public class EDocAnalysisUtils {

    /**
     * @param filePath 文件路径
     * @return 返回map
     * @throws IOException
     */
    public static Map<String,List<List<String>>> getE(String filePath) throws IOException {
        Path path = Paths.get(filePath);
        List<String> stringList = Files.readLines(path.toFile(), Charset.defaultCharset());
        Map<Boolean, List<String>> booleanListMap = stringList.stream().collect(Collectors.groupingBy(s -> s.contains("<")));
        List<String> keyList = booleanListMap.get(true);
        List<Integer> indexList = keyList.stream().map(s -> stringList.indexOf(s)).collect(Collectors.toList());
        Map<String,List<List<String>>> hashMap = new HashMap<>();
        hashMap.put(keyList.get(0),null);
        for (int i = 2; i < indexList.size(); i = i + 2) {
            hashMap.put(keyList.get(i - 1),
                    stringList.subList(indexList.get(i - 1) + 3, indexList.get(i))
                            .stream().map(s -> s.replace("#\t", "")).map(s -> Arrays.asList(s.split("\\s+"))).collect(Collectors.toList()));
        }
        return hashMap;
    }
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值