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. 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.
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:
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
As you can see, the output includes a bunch of ugly symbols. How can I use UTF-8 given my current program?
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 "";
}
}
}