How to get InputStreamReader in ISO-8859-15?

fred picture fred · Aug 21, 2011 · Viewed 9.9k times · Source

How can I make this inputstream read a ISO-8859-15 encoded file?

BufferedReader r = new BufferedReader(new InputStreamReader(getResources().openRawResource(R.raw.jet)));

I found this line which seemingly works:

BufferedReader br = new BufferedReader(new InputStreamReader(ftp.getInputStream(), "ISO-8859-15"));

But

BufferedReader r = new BufferedReader(new InputStreamReader(getResources().openRawResource(R.raw.jet), "ISO-8859-15"));

does not.

Answer

fred picture fred · May 3, 2012

It seems that:

BufferedReader r = new BufferedReader(new InputStreamReader(getResources().openRawResource(R.raw.jet), Charset.forName("ISO-8859-15")));

works. Apparently you need to send a Charset, not a String with the encoding in this case. Given this it seems strange that this works then:

BufferedReader br = new BufferedReader(new InputStreamReader(ftp.getInputStream(), "ISO-8859-15"));