【问题标题】:Is there any way to read text from .fdt/.fdx/.fdxt ftile from java?有什么方法可以从 java 的 .fdt/.fdx/.fdxt ftile 读取文本?
【发布时间】:2020-01-08 03:43:36
【问题描述】:

我要统计.fdt/.fdx/.fdxt文件的字数

我将 .fdxt 转换为 .html 然后进一步解析它。它在某些情况下是成功的,但不是全部。

    String html="";

    Scanner sc = new Scanner(new File("/home/de-10/Desktop/1.html"));
    while(sc.hasNextLine()) {
        html+=sc.nextLine();
    }
    sc.close();

    System.out.println(html);

    Document doc = Jsoup.parse(html.toString());
    String data = doc.text();
    System.out.println(data);

    Scanner sc1 = new Scanner(new String(data));
    int wordCount=0;
    while(sc1.hasNext()) {
        sc1.next();
        wordCount++;
    }
    sc1.close();

    System.out.println("");
    System.out.println("**********");
    System.out.println("WordCount: "+wordCount);
    System.out.println("**********");
    System.out.println("");

我正在寻找一些最佳解决方案。

【问题讨论】:

  • 当我说“我将 .fdxt 转换为 .html”时,我只是将 .fdxt 重命名为 .html

标签: java html parsing html-parsing fdt


【解决方案1】:

你说,“它在某些情况下是成功的,但不是全部”。所以我建议在计数之前从文本中删除标点符号。

int wordCount = Jsoup.parse(html).text().replaceAll("\\p{Punct}", "").split("\\s+").length;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-21
    • 2021-03-25
    • 2020-04-11
    • 2010-10-28
    • 1970-01-01
    相关资源
    最近更新 更多