Well, I was trying to read a text file encoded in ISO-8859-7 and save it in UTF-8 or vice versa since the text file contains Greek/Latin text. I realised that it wasn't so easy (as stated in this question).
But I also noted that when I read my text file encoded in UTF-8 and try to save it to ISO-8859-7 it actually works as supposed (writing readable characters in the text file). On the other hand, when the opposite case is true, reading ISO-8859-7 and writing UTF-8 then the outcome is not the expected one.
So, my question is why the above occurs? I know I should have followed the approach in the question so I don't need an answer about how to make the encoding work. Does it have to do with the fact that UTF-8 defines more characters than ISO-8859-7?
I am using the following code to accomplish this:
BufferedReader reader = BufferedReader(new InputStreamReader(new FileInputStream(file), encoding));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), encoding));
where encoding
is just a String
representing the encoding.