JAVA 遍历UFT-8所有中文

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class Chinese {

    public static void main(String[] args) {

        int start = Integer.parseInt("4e00",16);
        int end = Integer.parseInt("9fa5",16);

        StringBuilder stringBuilder = new StringBuilder();

        for (int i = start; i < end; i++) {
            stringBuilder.append((char) i);
            stringBuilder.append('\n');
        }

        try {
            // 文件保存到项目目录下
            File file = new File("text.txt");
            file.createNewFile();
            FileWriter fileWriter = new FileWriter(file);
            fileWriter.write(stringBuilder.toString());
            fileWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}
上一篇:python – TensorFlow FileWriter没有写入文件


下一篇:JAVA FileWriter写数据到文本文件