java - listFiles(), isDirectory() 方法无法读取 java 1.4 中的 unicoded 数据

标签 java unicode lucene

我正在使用 Java 1.4 作为我的客户端要求以及 lucene-core-2.9.2.jarlucene-demos-2.9.2。 jar 。我正在使用 Ant 进行构建。它适用于除 Unicodescandic char 之外的所有目录。

当我尝试使用 listFiles() 列出时,它列出了除 unicoded 之外的所有数据,显示为 block 。当它想使用isDirectory()读取列表时,它不能定义那些用于索引的文件夹名称是其他语言(包含unicodescandic char).

如何使用 unicoded 数据和 scandic char 解决这个问题?

如果我使用 Java 6 或 7,它运行良好。所以根据客户需求(Java 1.4),请不要告诉我使用 Java 5,6 或 7。提供其他有值(value)的答案。作为您的最佳理解,我在下面添加了我的代码

public void addIntoIndex(File dir, IndexWriter indexWriter) {       
try {
    System.out.println("Now in addIntoIndex");
    File[] htmls = dir.listFiles();

    /** "Release_Notes" folder will be excluded for indexing */
    if(dir.getName().equals("Release_Notes") && this.searchOption.equals("systemHelp")) {
        System.out.println("'Release_Notes' folder will be excluded for indexing.");
        return;
    }

    for(int i = 0; i < htmls.length; i++){
        String htmlPath = htmls[i].getAbsolutePath();   

        if(htmls[i].isDirectory()) {
            addIntoIndex(new File(htmls[i].getAbsolutePath()), indexWriter);
        }

        if(htmlPath.endsWith(".html") || htmlPath.endsWith(".htm")){
            addDocument(htmlPath, indexWriter);
        }
    }

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

最佳答案

我的问题终于解决了。实际上,我正在为我所有的 html 文件编制索引,这些文件为

<html>
<head>..</head>
<body>...</body>
</html>

采用这种格式。

在 head 部分添加以下两行后,这个问题在我的 java 1.4.02 版本中解决了。

<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<meta http-equiv="content-script-type" content="text/javascript; charset=UTF-8"/>

特别感谢我的项目经理和Peter Lawreytxtechhelp

关于java - listFiles(), isDirectory() 方法无法读取 java 1.4 中的 unicoded 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20630273/

相关文章:

elasticsearch - 为什么在 Elasticsearch 中创建150个滚动上下文?

java - 由于重新平衡,无法完成提交

java - java.utils.HashMap 中的 Node.equals 方法

java - 如何使方法接受包含任何数据类型对象的列表

python - 正则表达式和 unicode 文字

java - Hibernate Search 空间构面查询首先运行 5 次,然后仅返回第 5 个结果

solr - 如何配置 Solr 进行部分词匹配

java - 创建 "Service"bean 时出错

python - 在 Python 中使用带有 LOCALE 和 UNICODE 标志的 Regex 测试空格

python - 如何使用 BeautifulSoup 查找 HTML 页面中 <p> 元素内的所有文本