简体   繁体   English

如何更改我的程序以便它可以使用 UTF-8 进行编码?

[英]How to change my program so that it can encode with UTF-8?

I am a linguist, so I wrote a program to help me analyze language text by putting sentences and their translations next to each other.我是一名语言学家,所以我编写了一个程序来帮助我分析语言文本,方法是将句子和它们的翻译并排放置。

INPUT:输入:

Läänemere nõgu on kujunenud Kvaternaarieelsel ajal maakoore kõikuvliikumiste ja kauaste uuristus- ja kulumisprotsesside toimel. Läänemere nõgu on kujunenud Kvaternaarieelsel ajal maakoore kõikuvliikumiste ja kauaste uuristus- ja kulumisprotsesside toimel。 Neogeeni lõpus oli nüüdse Läänemere nõos keerukas jõestik. Neogeeni lõpus oli nüüdse Läänemere nõos keerukas jõestik。 Soome lahe kohal voolanud Ürg-Neevasse suubusid Põhja-Eesti alalt nüüdisjõgedest tunduvalt suuremad lisajõed. Soome lahe kohal voolanud Ürg-Neevasse suubusid Põhja-Eesti alalt nüüdisjõgedest tunduvalt suuremad lisajõed。

The Baltic Sea basin has been formed in the pre-Quaternary period as a result of fluctuations in the earth's crust and long-term exploration and wear processes.波罗的海盆地形成于前第四纪,是地壳波动和长期勘探磨损过程的结果。 At the end of the Neogene, there was a complex river basin in what is now the Baltic Sea basin.在新近纪末期,在现在的波罗的海盆地中有一个复杂的河流盆地。 Ancient rivers much larger than modern rivers flowed into the primeval Neva River, which flowed over the Gulf of Finland.远大于现代河流的古代河流流入原始涅瓦河,流经芬兰湾。

OUTPUT: OUTPUT:

Läänemere nõgu on kujunenud Kvaternaarieelsel ajal maakoore kõikuvliikumiste ja kauaste uuristus- ja kulumisprotsesside toimel The Baltic Sea basin has been formed in the pre-Quaternary period as a result of fluctuations in the earth's crust and long-term exploration and wear processes Neogeeni lõpus oli nüüdse Läänemere nõos keerukas jõestik At the end of the Neogene, there was a complex river basin in what is now the Baltic Sea basin Soome lahe kohal voolanud Ãœrg-Neevasse suubusid Põhja-Eesti alalt nüüdisjõgedest tunduvalt suuremad lisajõed Ancient rivers much larger than modern rivers flowed into the primeval Neva River, which flowed over the Gulf of Finland Läänemere nõgu on kujunenud Kvaternaarieelsel ajal maakoore kõikuvliikumiste ja kauaste uuristus- ja kulumisprotsesside toimel 波罗的海盆地形成于前第四纪,是地壳波动和长期勘探磨损过程的结果 Neogeeni lõpus oli nüüdse Läänemere nõos keerukas jõestik 在新近纪末期,在现在的波罗的海盆地中有一个复杂的河流盆地比现代河流大得多的河流流入原始的涅瓦河,流经芬兰湾

As you can see, the output includes a bunch of ugly symbols.如您所见,output 包含一堆丑陋的符号。 How can I use UTF-8 given my current program?给定我当前的程序,如何使用UTF-8

public String fileParse(String filename) {
        
    final String HOMEDIR = "C:\\Users\\(my name)\\Desktop\\";
    
    try {
        File myObj = new File(HOMEDIR + filename);
        Scanner myReader = new Scanner(myObj);
        StringBuilder first_string = new StringBuilder();
        while (myReader.hasNextLine()) {
          String data = myReader.nextLine();
          first_string.append(data);
        }
        myReader.close();
        String other_string = first_string.toString();
        String[] split_string = other_string.split("\\.");
        int the_integer = split_string.length / 2;
        StringBuilder final_output = new StringBuilder();
        for (int i = 0; i < the_integer; i++) {
            final_output.append(split_string[i] + " " + split_string[i + the_integer] + "\n");
        }
        return final_output.toString();
        
        
      } catch (FileNotFoundException e) {
        System.out.println("An error occurred.");
        e.printStackTrace();
        return "";
      }
    

    
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM