zoukankan      html  css  js  c++  java
  • JAVA读取本地html文件里的html文本

    /**
         *  读取本地html文件里的html代码
         * @param file  File file=new File("文件的绝对路径")
         * @return
         */
        public static String toHtmlString(File file) {
            // 获取HTML文件流
            StringBuffer htmlSb = new StringBuffer();
            try {
                BufferedReader br = new BufferedReader(new InputStreamReader(
                        new FileInputStream(file), "utf-8"));
                while (br.ready()) {
                    htmlSb.append(br.readLine());
                }
                br.close();
                // 删除临时文件
                //file.delete();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            // HTML文件字符串
            String htmlStr = htmlSb.toString();
            // 返回经过清洁的html文本
            return htmlStr;
        }
    -----------------------有任何问题可以在评论区评论,也可以私信我,我看到的话会进行回复,欢迎大家指教------------------------ (蓝奏云官网有些地址失效了,需要把请求地址lanzous改成lanzoux才可以)
  • 相关阅读:
    Many Equal Substrings CF
    Seek the Name, Seek the Fame POJ
    人人都是好朋友(离散化 + 并查集)
    建设道路
    day_30
    day_29作业
    day_29
    day_28
    day_27
    day_26作业
  • 原文地址:https://www.cnblogs.com/pxblog/p/14645201.html
Copyright © 2011-2022 走看看