• 读rtf文件


    教学立方挂了,由于要录作业讲解视频,恰好之前下载过同学们的作业,所以直接读文件找满分作业比较容易,就参考了代码写了一下。

    https://blog.csdn.net/navi617211950/article/details/52540364

    https://blog.csdn.net/tian_sweety/article/details/81871864

    两个来源

    import javax.swing.text.BadLocationException;
    import javax.swing.text.DefaultStyledDocument;
    import javax.swing.text.rtf.RTFEditorKit;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.nio.charset.StandardCharsets;
    import java.util.ArrayList;
    import java.util.Arrays;
    
    public class ReadRTF {
    
        public static void getAllFileName(String path, ArrayList<String> listFileName) {
            File file = new File(path);
            String[] names = file.list();
            if (names != null) {
                String[] completNames = new String[names.length];
                for (int i = 0; i < names.length; i++) {
                    completNames[i] = path + "\" + names[i];
                }
                listFileName.addAll(Arrays.asList(completNames));
            }
        }
    
        public static String getTextFromRtf(String filePath) {
            String result = null;
            File file = new File(filePath);
            try {
                DefaultStyledDocument styledDoc = new DefaultStyledDocument();
                // 创建文件输入流
                InputStream streamReader = new FileInputStream(file);
                new RTFEditorKit().read(streamReader, styledDoc, 0);
                result = new String(styledDoc.getText(0, styledDoc.getLength()).getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8);
            } catch (IOException | BadLocationException e) {
                e.printStackTrace();
            }
            return result;
        }
    
    
        public static void main(String[] args) throws IOException {
            ArrayList<String> listFileName = new ArrayList<>();
            getAllFileName("D:\...\数据库开发技术_21 课后思考题_02月23日12时16分", listFileName);
            for (String name : listFileName) {
                if (name.contains(".rtf")) {
                    String result = getTextFromRtf(name);
                    if(result.contains("教师打分:5分")) {
                        System.out.println(result);
                    }
                }
            }
        }
    
    }
    
  • 相关阅读:
    git 从远程仓库指定分支克隆代码到本地
    vue路由懒加载
    ES6中拓展运算符 ...
    Mysql 安装-windows X64
    mysql-Federated存储方式,远程表,相当于sql server的linked server
    优化临时表使用,SQL语句性能提升100倍
    MySQL行锁深入研究
    mysql 队列 实现并发读
    mysql 常用sql
    mysql分表的3种方法
  • 原文地址:https://www.cnblogs.com/angelica-duhurica/p/12380832.html
Copyright © 2020-2023  润新知