UTF8 problem in Java

Discussion in 'Software' started by mabs, Mar 18, 2009.

  1. mabs

    mabs

    Joined:
    Mar 18, 2009
    Messages:
    2
    Hi All,

    I am trying to read a web page. It contains unicoded forign language characters. I want to save that particular information only. But if I save the whole page, it looks normal and is written as UTF-8. But when I write only the particulatar string in it, it look as garbage. Infact the file is saved as ANSI. What should I do now?

    URL url1 = new URL("-----");
    BufferedReader in = new BufferedReader( new InputStreamReader(url1.openStream()));
    PrintWriter out= new PrintWriter(new BufferedWriter(new FileWriter("test.txt")));
    String str;
    int n = 0;

    while ((str = in.readLine()) != null){

    if(str.contains("<td class='urdu-cell' align=right valign=top>") )

    {
    n=str.indexOf("<td class='urdu-cell' align=right valign=top>");
    str = str.substring( n,n+str.indexOf("td") );
    out.print(str);
    }
    }//wend
    in.close();
    out.close();
    mabs, Mar 18, 2009
    #1
    1. Advertising

  2. mabs

    mabs

    Joined:
    Mar 18, 2009
    Messages:
    2
    So sorry that I cannt post the URL link
    mabs, Mar 18, 2009
    #2
    1. Advertising

  3. mabs

    susith

    Joined:
    Feb 25, 2009
    Messages:
    16
    Use constructor

    charsetName="UTF-8";
    public InputStreamReader(InputStream in,
    String charsetName)
    susith, Mar 27, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fernando Kohan

    JAVA VIRTUAL MUCHINE OR SUN JAVA

    Fernando Kohan, Nov 13, 2004, in forum: Firefox
    Replies:
    1
    Views:
    747
    Clark
    Nov 14, 2004
  2. dakine

    MS Java or Sun Java???

    dakine, Jul 20, 2004, in forum: Computer Support
    Replies:
    9
    Views:
    1,435
  3. emerald
    Replies:
    3
    Views:
    12,710
    The Modfather
    May 14, 2006
  4. chuck

    Firefox and Java - but no Java

    chuck, Mar 19, 2007, in forum: Firefox
    Replies:
    1
    Views:
    340
    Peter.Potamus.the.Purple.Hippo@gmail.com
    Mar 19, 2007
  5. -Dan-
    Replies:
    0
    Views:
    530
    -Dan-
    Aug 5, 2005
Loading...

Share This Page