I've got a .txt File, which contains millions of postalcodes.
There are all well-formatted (readable).
My Goal is, to import the postalcodes into a MySql-Database.
I need to convert the postalcodes from the .txt File into a .sql File.
I wrote an Java Application to Convert the important parts into an SQL-File.
EDIT: The .txt File contains many information. That's why I want to read the File (In Java), filter the File content and finally create a .sql File. Many thanks to any Solution written in "Python, SQL, C++, BrainF***" or other languages, but I would appreciate a Solution for my specific Java Code. The .txt File uses UTF-8 encoding.
After convert into ".sql", the content has several issues.
For Example the Cyrillic Character "Я" is not "known" in the SQL-File.
I assume, that the encoding is wrong.
It would be nice, if someone could help me to get a clue how to resolve this.
TXT-File: TXT-File
SQL-File: SQL-File
try (BufferedReader br = new BufferedReader(
new FileReader(GeoData.class.getResource(sourceFilenameInput.getText().trim()).getFile().trim()))) {
for (String line; (line = br.readLine()) != null;) {
GeoData geoData = new GeoData();
geoData.addOrt(getPlaceFromFile(line));
}
getPlaceFromFile Method:
private String getPlaceFromFile(String line) {
String[] placeHolder = line.split("\t");
if (placeHolder .length > 2) {
for (int i = 0; i < placeHolder .length - 2; i++) {
if (!placeHolder [i + 2].trim().isEmpty() && placeHolder [i + 2].trim().length() > 3) {
return filterPlace(placeHolder [i + 2].trim(), "'", "\\", "^", ";", "*", "|");
}
}
}
return "EMPTY";
}
FilterPlace Method:
private String filterPlace(String place, String... filter) {
String newPlace = place;
for (String string : filter) {
if (newPlace .trim().contains(string))
newPlace = newPlace .trim().replace(string, " ");
}
return newPlace;
}
What have I tried so far?
I replaced the FileReader
with an InputStreamReader
and used the FileInputStream
with the Charset UTF-8. After converting in UTF-8 the SQL-File looked like this:
UTF8 Converted SQL-FILE