Problems reading an html page encoded in UTF-8

I'm trying this code with eclipse:
public class TestBooking {
      * @param args
     public static void main(String[] args) throws Exception {
          URL url;
          String url_string="http://www.booking.com/searchresults.html?checkin_monthday=21;checkin_year_month=2007-8;checkout_monthday=22;checkout_year_month=2007-8;class_interval=1;offset=0;si=ai%2Cco%2Cci%2Cre;ss_all=0;city=-126693";
          url = new URL(url_string);
          URLConnection connection = url.openConnection();
          HttpURLConnection httpConnection =(httpURLConnection)connection;
          InputStream input=connection.getInputStream();
          BufferedReader prova=new BufferedReader(new InputStreamReader(input));
          String str;
          while ((str=prova.readLine())!=null)
               System.out.println(str);
}And I get in the console a strange set of charachers:
<link rel="alternate" hreflang="el" href="/searchresults.el.html?sid=f190f46ada5404fc896b33035b20d50d;checkin_monthday=21;checkin_year_month=2007-8;checkout_monthday=22;checkout_year_month=2007-8;city=-126693;class_interval=1;offset=0;si=ai%2Cco%2Cci%2Cre" title="������������" />
instead of the correct:
<link rel="alternate" hreflang="el" href="/searchresults.el.html?sid=f190f46ada5404fc896b33035b20d50d;checkin_monthday=21;checkin_year_month=2007-8;checkout_monthday=22;checkout_year_month=2007-8;city=-126693;class_interval=1;offset=0;si=ai%2Cco%2Cci%2Cre" title="&#917;&#955;&#955;&#940;&#948;&#945;" />
How can I fix the problem to read the input correctly?
Thanks for help.

No conversion is needed, just specify the encoding when you create your InputStreamReader. But you can't expect text in all those different scripts to display correctly in your console. Even if the console is configured to use an encoding like UTF-8 that can handle all the characters, it won't be using a font with all the appropriate glyphs. But, like you said, it doesn't matter if you can't display all of the page's source code correctly. All you need is to be able to read it, which means using the correct encoding.

Similar Messages

  • Problem in Opening HTML Page in Internet Explorer from my Swing Application

    Hi,
    I am opening a HTML file in Internet Explorer from my swing application.I am using the code given below
    private final static String WIN_FLAG = "url.dll,FileProtocolHandler";
    private final static String WIN_PATH = "rundll32";
    String cmd = WIN_PATH + " " + WIN_FLAG + " " + url;
    // url is HTML file Path
    Process p = Runtime.getRuntime().exec( cmd );
    Here there are two things i need to address ...
    1)The HTML file is opening up,but it always opens behind the swing application,that makes me every time to maximize the HTML file after it being opened up.I want to open it in front of the Swing Application.I need to implement "Always On Top" functionality for the html page.
    2)Whenever i trigger action to open different HTML page,it opens in new Internet Explorer window.
    I need to open it in same IE window.
    how to solve out these problems ??? any help would be greatly appreciated .Thanks in advance.
    - Manikandan

    any idea about this ????

  • Problem in refreshing html page using LinkToURL API

    Hi all,
    I use LinkToURL in order to open a html page in a new window. My problem is that this html file is changed (the name is the same but the contents is diff) dynamically. I click on the link and the window is open, but later on when the html file is changed and I reopen the window it shows the old html file. Is it possible to refresh this window automatically every time when it is opened? Otherwise the user has to press Refresh button in order to see the new html file.
    10x for your help.
    Svetlomira

    Hi Svetlomira,
    Do you have access to html file? Can you changed it?
    Or you can use following approach: if html is static (not jsp or asp or similar)
    you can append System.currentTimeMillis() to the html file name after '?' sign:
    final String nonCachedURL = "http://www.domain.com/index.html?" + System.currentTimeMillis();
    You can achieve this by using calculated context attribute and bind it with LinkToUrl`s reference proprty.
    Best regards, Maksim Rashchynski.

  • Problem sending a HTML page

    How can i send a HTML by email??
    When i am sending a HTML he shows the code in the mail instead of showing the HTML page??
    Anyone knows how can i solve tyhis??

    are you setting the content type to text/html? there are plenty of examples out there (and in here). run a search.

  • Problem in Printing HTML page

    While I am trying to print a HTML page using window.print(), the bgcolor of the table is not printing.

    Did you consider inquiring about this at a Javascript or HTML forum?

  • Reading an HTML page in Java

    I have done some server-side java coding before but nothing quite like this. I want to parse and HTML and extract information from it to process and create a new HTML page. This sounds like it should be easy enough, I just don't know where to start. Can anyone give me a pointed to the correct package/class(es) to research?
    If you are curious to know what I am planning on doing, read on. I am part of a Yahoo NFL Picks competition and I think it would greatly benefit from having a "What If?" scenario analyzer. Currently it does not. However, I can access each member's public picks page, extract their predictions, compare against my own predictions and then enter in results for games yet to be played. There are 46 members so I would need to read in 46 HTML pages, collect the predictions and then process the information. I'm pretty god at figuring out how to use classes, etc., I am just a little unsure of where to start looking.
    TIA, Max

    i know you could use JEditorPane
    here a code i found somewhere, already try it, its works:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import javax.swing.event.*;
    import java.net.*;
    import javax.swing.text.*;
    public class Browser extends JFrame {
         Browser() {
              getContentPane().setLayout (new BorderLayout (5, 5));
              final JEditorPane jt = new JEditorPane();
              final JTextField input =
              new JTextField("http://java.sun.com");
              // make read-only
              jt.setEditable(false);
              // follow links
              jt.addHyperlinkListener(new HyperlinkListener () {
                   public void hyperlinkUpdate(
                   final HyperlinkEvent e) {
                        if (e.getEventType() ==
                             HyperlinkEvent.EventType.ACTIVATED) {
                                  SwingUtilities.invokeLater(new Runnable() {
                                       public void run() {
                                            // Save original
                                            Document doc = jt.getDocument();
                                            try {
                                                 URL url = e.getURL();
                                                 jt.setPage(url);
                                                 input.setText (url.toString());
                                            } catch (IOException io) {
                                                 JOptionPane.showMessageDialog (
                                                 Browser.this, "Can't follow link",
                                                 "Invalid Input",
                                                 JOptionPane.ERROR_MESSAGE);
                                                 jt.setDocument (doc);
              JScrollPane pane = new JScrollPane();
              pane.setBorder (
              BorderFactory.createLoweredBevelBorder());
              pane.getViewport().add(jt);
              getContentPane().add(pane, BorderLayout.CENTER);
              input.addActionListener (new ActionListener() {
                   public void actionPerformed (ActionEvent e) {
                        try {
                             jt.setPage (input.getText());
                        } catch (IOException ex) {
                             JOptionPane.showMessageDialog (
                             Browser.this, "Invalid URL",
                             "Invalid Input",
                             JOptionPane.ERROR_MESSAGE);
              getContentPane().add (input, BorderLayout.SOUTH);
         public static void main(String args[])
              Browser bro = new Browser();
              bro.setSize(500,500);
              bro.setVisible(true);
    }hope that help

  • Problem in displaying html page in JEditorPane....

    Hi All,
    i was trying to display a html page in a JEditorPane. i was able to do that when i'm displaying a html page from a local machine.. But when i try to get the page from some website, it giving me
    "exception access denied (java.net.SocketPermission www.java.sun.com resolve)"
    exception. But if i run the same code thru JBuilder, its working. But thru appletviewer or thru IE or Netscape its throwing the error.. Any suggestion or help is highly appreciated....
    Thanks
    Ragu

    Java Applets are very secure, what is good. Java applets are extremely secure
    what is bad. So Applet cannot open TCP connection to any host rather than its
    home host. So you cannot get the resources from any other server (what is common to
    HTTP).
    In JBuilder iit works cause JBuilder is used for development and security in deevelopment
    is not an issue. But it confuses then you see.
    vpanasenko_even

  • Problem with opening html page in Dreamweaver

    Hello,
    I would like to ask the forum because I have a problem with Dreamweaver 8.
    In the past when I work with my PC on Windows XP I didn't have this problem.
    Now I have a new PC with Windows 7 Familial Edition Premium.
    I can open he most pages I would like, .htm particuliarly but some of them like .html don't opened in Dreamweaver 8
    on PC with Windows 7.
    Example:
    With this page: http://www.pb-veille-consulting.com/veille.html
    I can open it with Dreamweaver 8 under Windows XP on my portable PC.
    But I can't open it with Dreamweaver 8 under Windows 7 on my fix PC.
    Where is the problem?
    You could watch the code of this page and perharps give me answers from my question.
    Thanks a lot.
    Patrick.

    It could be that Extensions.txt and MMDocumentTypes.xml do not have the full set file extensions.
    The first one can be located at ~username/AppData/Roaming/Adobe/Dreamweaver CS6/en_us/Configuration and needs to have HTML added to line 1
    The second one can be located at ~username/AppData/Roaming/Adobe/Dreamweaver CS6/en_us/Configuration/DocumentTypes and needs to have HTML added to line 3 so that it looks like
    <documenttype id="HTML" internaltype="HTML" winfileextension="html,htm,shtml,shtm,stm,tpl,lasso,xhtml" macfileextension="html,htm,shtml,shtm,tpl,lasso,xhtml,ssi" file="Default.html" writebyteordermark="false" mimetype="text/html">

  • Problem reading a 30-page doc with Adobe Acrobat DC for Android

    I regularly upload Les Echos (French biz newspaper) on their website (http://www.lesechos.fr/pdf.php/20150413_LEC.pdf). After reading about 25-30 pages, the document closes itself, without prior notice and without saving any comments you may have made in the document.
    This problem first occurred early February, when Les Echos decided to produce "lighter" pdf newspapers and it has happened on every single issue since then. Never before.
    I contacted Les Echos to see if they could fix the problem. They answered that it was an Adobe problem.
    So, my question remains the same: can you (or anyone else) fix that?
    Thanks for your help.

    It seems that a login is required to access the PDF file you have linked us to. Would it possible for you to share a copy of the PDF by uploading it to Dropbox/Google Drive or mail the same to [email protected]? It will help us in understanding your issue better.
    Thanks.

  • Problem reading macports man pages while SSH'd in

    For some reason when a user SSH's in to one of our systems, they cannot read macports installed man pages. If I'm logged in on directly on the server - meaning I'm at the console - I can read the ports man pages, but if I SSH in from remote system, I can't.
    For example, locally on the server both man port and man doxygen produce man pages. Whille SSH'd in, those commands return: No manual entry for [command issued]
    Is this potentially a pathing issue where, for example, local (console) bash pathing gets set, but doesn't get passed when a user comes in via SSH?
    Honestly, yesterday we upgraded to 10.7.4. so I can't say for sure whether this is a 'new' problem or a known problem.
    Thanks much in advance - this is driving us nuts.

    In what way does that other process expect its input?
    My guess was
    that it expected a newline (\n) after every input
    field. The spawned application is not written by me but it puts the string to enter the username and waits for username, then password and does some validation check and asks again for directpath. Yes the it expects newline after every input.
    // output in shell
    D:\manish\martusproj>c:\Martus\bin\java.exe Xbootclasspath/p:c:\Martus\lib\ext\
    bc-jce.jar -cp c:\Martus\martus.jar org.martus.client.tools.ImportXmlBulletins -
    -import-directory=.\ --account-directory=c:\Martus
    Martus Bulletin XML Importer
    Enter User Name:mregmi
    Enter Password:hello
    Enter Martus folder name where you want these bulletins to be stored:mart
    Importing:Bulletin #1
    Importing:Bulletin #2
    Finished! 2 bulletins imported into Martus.
    Your process has
    to write exactly what that other process expects.
    Of course you can close the writer when you're done.
    kind regards,
    Jos
    ps. what happens if you change that 'flush' to
    'close' in my example?flush hangs.
    close works but the spawned app says invalid input.
    // output
    Martus Bulletin XML Importer
    java.lang.NullPointerException
         at org.martus.client.tools.ImportXmlBulletins.createSecurityObject(Unknown Source)
         at org.martus.client.tools.ImportXmlBulletins.main(Unknown Source)
    Exception in thread "main"
    Enter User Name:Enter Password:
    xml2martus Error code 1
    Convertion Complete.....
    the same command works from cmd.
    regards
    Manish

  • Problem reading external HTML format from text file

    I have a text file containing html formatted text which I try to get into a textfield.
    All works fine locally and even on my localhost test server, but when uploading to the real server - I get a blank.
    Anyone have any ideas? THANKS
    The text file :
    &t2=<TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Comic Sans MS" SIZE="14" COLOR="#FF0000" LETTERSPACING="0" KERNING="0">Some text here</FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Comic Sans MS" SIZE="14" COLOR="#FF0000" LETTERSPACING="0" KERNING="0">One more line</FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Comic Sans MS" SIZE="14" COLOR="#FF0000" LETTERSPACING="0" KERNING="0">And more text here</FONT></P></TEXTFORMAT>
    and the AS code in the movie:
    viewData.onPress = function() {
         //get text
         loadText()
    var tz
    function loadText() {
    var my_lv:LoadVars = new LoadVars();
    my_lv.onLoad = function(success:Boolean) {
      if (success) {
      //trace(this.toString())
      mytext.htmlText= this.t2;
      } else {
      //trace("Error loading/parsing LoadVars.");
    my_lv.load("myfile.txt");

    Thanks kglad, I did it and it made me find the real problem:
    The text file is generated by PHP script that gets an html formated text from flash (it is an online editing part of an application):
    the AS code to call the php:
    var send_lv:LoadVars = new LoadVars();
    send_lv.t1 = "&t2="+editor.t1.htmlText+"&";
    send_lv.sendAndLoad("write.php", res_lv, "POST");
    the PHP:
    <?php
    $mydata = $_POST["t1"];
    $myFile = "recipe.txt";
    $fh = fopen($myFile, 'w') or die("can't open file");
    fwrite($fh, $mydata);
    fclose($fh);
    print "&done=done";
    ?>
    From some reason the online server adds \ before any " , but WAMP doesn't.
    here is the text generated on localhost (WAMP)
    &t2=<TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Comic Sans MS" SIZE="14" COLOR="#FF0000" LETTERSPACING="0" KERNING="0">local text</FONT></P></TEXTFORMAT>&
    online server:
    &t2=<TEXTFORMAT LEADING=\"2\"><P ALIGN=\"LEFT\"><FONT FACE=\"Comic Sans MS\" SIZE=\"14\" COLOR=\"#FF0000\" LETTERSPACING=\"0\" KERNING=\"0\">online text</FONT></P></TEXTFORMAT>&
    I know its not a Flash problem now, but do you have any idea?
    Thanks

  • Jawin mshtml read  a html page  using the MS IE

    is there some place I can find jawin codes to handle MSHTML.dll
    i'm new to jawin and seem to see a big library that is relatively empty

    Swing related questions should be posted in the Swing forum.
    im not looking forward to writting the work around.Maybe the following will work:
    EditorKit kit = new HTMLEditorKit();
    HTMLDocument doc = (HTMLDocument)kit.createDefaultDocument();
    doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
    messageBodyArea.setContentType("text/html");
    messageBodyArea.setEditorKit(kit);
    messageBodyArea.read(sRead, doc);

  • Problem open new html page from flash

    Hello,
    in IE7 and IE8 block popup lock my external link(page html)
    I use GetUrl(url,"_blank") but not it works
    Why?
    i use flash cs4
    With firefox it work

    thank you for response,
    i have used correct command but not it works.
    It Works, in my popup setting are setting "CUSTOM" not MEDIUM
    thank you

  • Having problems reading pdf in safari (encoding)?

    I'm having problems with reading pdf files on safari.  What is the fix?

    And carefully read what Adobe advise customers to do:
    "Adobe recommends customers stay with Mac OS 10.6 and Safari 5.0.x in order for in-browser use cases to continue to function."
    Apple Safari 5.1 and Adobe Reader/Acrobat Advisory
    As of today Safari can not display the pdf files from the on-line libraries around the globe but the user can download the pdf file, and then it shows up.
    I guess this is yet another reason to stay with the 10.6.8 Mac OS.

  • Problem in the HTML Page

    Hello All,
    In our SUS system , PO Response tab is visible in Dev system and its not visible in Test System.
    Can you please tell me which settings is missing in Test System and How to find the root cause of the problem.
    Assured Points !!
    Thanks in Advance.

    Hi,
    It may be related to the data, can you check the SRM PO in your test SRM system and make sure PO response is checked in the SRM PO.
    Regards,
    Sreedhar Vetcha

Maybe you are looking for

  • Importing...stf or anybody else??

    i tried a simple jsp page and called my bean.it works fine. Now i created a tomcat/webapps/root/mypack folder and put it thr..and using page import am importing but getting the foll errors: Error: 500 Location: /BeanTest.jsp Internal Servlet Error: o

  • Indesign going wrong when inserting a page

    HI, this is an unusual issue I have never encounters. I have A4 pages set up as facing in landscape mode and have created a document. However I have decided I need to insert a page towards the top of the document, when I do so all the master page ele

  • Problem in viewing a converted JavaHelp (jar) file (created using RH2002 to RoboHelp X5)

    Hi, I have a javahelp project (compressed javahelp) created using RoboHelp 2002. The output files are jar files. The source files are .mpj. When I view the existing jar files without converting the project to .xpj I am able to view the jar files. How

  • Which Method of Making USB Mavericks Installer?

    I use Mavericks OS X 10.9.1.  Which of the following methods should I use to make a USB Mavericks Installer/Re-Installer?: 1. How to Create an OS X Mavericks USB Installation Drive: lifehacker.com/how-to-create-an-os-x-mavericks-usb-installation-driv

  • Sort ArrayList of HashMaps

    Hello all I have Arraylist that contains HashMaps how can I sort the ArrayList by some value of HashMaps? e.g. I have following HashMaps that are put inside a list and need to sort them by there value ArrayList<HashMap> al = new ArrayList<HashMap>();