0

I am using BufferedReader to get data fro ma url.

 URL url = new URL("http://");
 BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream(), "windows-1251"));

On some url's encoding is windows-1251 (cyrilyc) so i specified that in the reader. But on some ones, enconding is different, e.g KOI8-R Any way to get the data from both sources without using naother reader? I really can use only one here.

artouiros
  • 3,947
  • 12
  • 41
  • 54

1 Answers1

2

No, the BufferedReader cannot examine the Content-Enconding header. You have to supply that. Or use a library for encoding recognition/detection.

Michael-O
  • 18,123
  • 6
  • 55
  • 121
  • If you need general enconding recognition, try [ICU4J](http://site.icu-project.org/). In the case you need something more HTTP/HTML specific, try the [Jericho HTML Parser]/http://jericho.htmlparser.net/docs/index.html) with it's [`Source`](http://jericho.htmlparser.net/docs/javadoc/net/htmlparser/jericho/Source.html#Source(java.net.URLConnection)) class. Also make sure that your JVM supports your encodings. – Michael-O Jul 23 '11 at 13:53