I have file that contains Unicode characters from Latin-1 and Latin Extended A sets (link to Unicode charts). How do I read it so that these unicodes are converted to proper characters?
I tried
public void readFile(File file) {
try {
BufferedReader in = new BufferedReader(new FileReader(file));
String noneUTF;
while ((noneUTF = in.readLine()) != null) {
byte[] utfBytes = noneUTF.getBytes("UTF8");
String str = new String(utfBytes, "UTF8");
jta.append(str + "\n");
}
in.close();
}
catch (IOException ioe) {
ioe.printStackTrace();
}
}
and
public void readFile(File file) {
StringBuffer buffer = new StringBuffer();
try {
FileInputStream fis = new FileInputStream(file);
InputStreamReader isr = new InputStreamReader(fis,
"UTF8");
Reader in = new BufferedReader(isr);
int ch;
while ((ch = in.read()) > -1) {
buffer.append((char)ch);
}
in.close();
System.out.println( buffer.toString());
} catch (IOException e) {
e.printStackTrace();
}
}
but I haven't got to much success :(