java - 列出带有 Unicode 字符的文件名(阿拉伯语)

标签 java directory arabic

我正在尝试获取目录及其子目录中的所有文件名。目录和文件的名称均为阿拉伯语。当我得到文件名时,它返回???标记而不是名称。有人之前遇到过这个问题吗?

    boolean recursive = true;
    Collection files = FileUtils.listFiles(root, null, recursive);

    //System.out.println(files.toString());

    PrintWriter success = new PrintWriter("E:\\success.txt", "UTF-8");

    for (int i = 0; i < list.size(); i++) {
        fileName = list.get(i);
        for (Iterator iterator = files.iterator(); iterator.hasNext();) {
            File file = (File) iterator.next();
            if (file.getName().endsWith(fileName)) {
                Files.copy(Paths.get(file.getAbsolutePath()),
                        Paths.get(targetDirectory + "\\" + file.getName()));
                success.println(fileName.toString());
            }
        }

    }

最佳答案

您尝试过UTF-16编码格式吗?

PrintWriter success = new PrintWriter("E:\\success.txt", "UTF-16");

编辑: 我认为UTF-8应该能够正确编码阿拉伯字符。这里的问题可能是您用来读取文件的文本编辑器。请检查您用来读取文件的文本编辑器的编码格式。在编辑器中将编码设置为 Unicode UTF-8 应该可以解决您的问题。

关于java - 列出带有 Unicode 字符的文件名(阿拉伯语),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52299023/

相关文章:

java - 在 Eclipse 中导入 jar 文件时出错(即使将其添加到构建路径后)

java - 为什么这个 O(n^2) 代码的执行速度比 O(n) 快?

php - 使用 .htaccess 将子目录设置为根目录

bash - 如何从脚本本身获取 Bash 脚本所在的目录?

ruby-on-rails - 具有非拉丁字符的 Rails 友好 ID

python - 正则表达式 match() 无法捕获 python 中的简单模式

c# - Lucene.Net 阿拉伯语

java.lang.IllegalStateException : Transaction not active after REMOVE object, hibernate

java - Futures、TimeoutException 和带有finally block 的Callables

python - 如何从代码配置 nltk 数据目录?