×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Regular Contributor
    Join Date
    Nov 2010
    Location
    Egypt,Mansoura
    Posts
    80

    i want to read form URL But not English

    When i read from url some information in English it's not problem

    the problem when this information is written in Arabic I use That Code :

    Code:
     private String work() {
            StreamConnection conn = null;
            boolean flag = false;
            boolean finished = false;
            boolean ss=false;
            InputStream in = null;
            StringBuffer str = new StringBuffer();
            //String str="";
            String url = "http://news.google.com/news?edchanged=1&ned=us";
            String fn="";
            int x=18;
            String f = null;
            byte[] data = null;
    
            try {
                conn = (StreamConnection) Connector.open(url);
                in = conn.openInputStream();
                int ch;
    
    
    
    
                while ((ch=in.read())!= -1 && !finished) {
    
                    if (((char) ch) == '<') {
                        flag = true;
                    }
                    if (flag) {
                        if (((char) ch) != '/') {
    
                          
                               str.append((char) ch);
                                ss=true;
                                
                            
                        } else  {
                            String line=new String(str.toString());
                            if(ss){
                                int position = line.indexOf("titletext");
                                if(position!=-1){
                                f=Integer.toString(line.length());
                                fn=line.substring(position+11, line.length()-1);
                                frm.append("\n");
                                frm.append(fn);
                                 frm.append("\n");
                                frm.append(f);
                               // Alert alert1=new Alert("d",fn,null,AlertType.INFO);
                               //display.setCurrent(alert1);
                                finished = true;
                                }
                            }
                             str = new StringBuffer();
                             
                            flag = false;
    
                            
                        }
                    }
                }
            } catch (Exception e) {
                System.err.println("The Connection could not be established buffon...");
            }
    
            return (fn);
        }
    How Can I get The Arabic Information In Arabic
    Let The Impossible Happen!!!

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    Location
    Finland
    Posts
    9,553

    Re: i want to read form URL But not English

    Is it on a phone that has Arabic support (fonts, in particular) built-in?

  3. #3
    Regular Contributor
    Join Date
    Nov 2010
    Location
    Egypt,Mansoura
    Posts
    80

    Re: i want to read form URL But not English

    Thanks I Found The Answer I will share it for others

    U Can Make An InputStreamReader Which read with the encoding that u Spicify to it For Arabic From The Interent of For Xml I Used "UTF-8" and It Work Fine

    This is the Code

    Code:
    InputStreamReader rs=new InputStreamReader(conn.openInputStream(),"UTF-8");
    U can replace the UTF-8 With Any System else From This List

    Code:
    US-ASCII
                              Seven-bit ASCII, a.k.a. ISO646-US, a.k.a. the Basic Latin block of the Unicode character set
    ISO-8859-1  
                             ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1
    UTF-8
                                Eight-bit Unicode Transformation Format
    UTF-16BE
                               Sixteen-bit Unicode Transformation Format, big-endian byte order
    UTF-16LE
                              Sixteen-bit Unicode Transformation Format, little-endian byte order
    UTF-16
                               Sixteen-bit Unicode Transformation Format, byte order specified by a mandatory initial byte-order mark (either order accepted on input, big-endian used on output)
    Thanks,

    BUFFON
    Last edited by buffon2009; 2011-01-19 at 16:29.
    Let The Impossible Happen!!!

  4. #4
    Super Contributor
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    814

    Re: i want to read form URL But not English

    one note, though :
    this
    str.append((char) ch);
    is very wrong and should never be used since it means assuming the enconding is 8-bit and is the same as your locale

  5. #5
    Regular Contributor
    Join Date
    Nov 2010
    Location
    Egypt,Mansoura
    Posts
    80

    Re: i want to read form URL But not English

    Quote Originally Posted by njzk2 View Post
    one note, though :
    this
    str.append((char) ch);
    is very wrong and should never be used since it means assuming the enconding is 8-bit and is the same as your locale
    Thanks for your note But i used UTF-8 Which is 8-bit Encoding
    Let The Impossible Happen!!!

  6. #6
    Super Contributor
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    814

    Re: i want to read form URL But not English

    Quote Originally Posted by buffon2009 View Post
    Thanks for your note But i used UTF-8 Which is 8-bit Encoding
    no it is not.
    http://en.wikipedia.org/wiki/UTF-8

  7. #7
    Regular Contributor
    Join Date
    Nov 2010
    Location
    Egypt,Mansoura
    Posts
    80

    Re: i want to read form URL But not English

    Ok , But How it is Work Fine For me????
    Let The Impossible Happen!!!

  8. #8
    Super Contributor
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    814

    Re: i want to read form URL But not English

    because in your second post, you indicate that you use an inputstreamreader, which reads characters based on the given encoding. my remark only applies to your first post, where you use an InputStream, which reads bytes.
    the inputstreamreader is one correct way to read a stream of characters.

  9. #9
    Regular Contributor
    Join Date
    Nov 2010
    Location
    Egypt,Mansoura
    Posts
    80

    Re: i want to read form URL But not English

    Quote Originally Posted by njzk2 View Post
    because in your second post, you indicate that you use an inputstreamreader, which reads characters based on the given encoding. my remark only applies to your first post, where you use an InputStream, which reads bytes.
    the inputstreamreader is one correct way to read a stream of characters.
    Ok Thanks I got it
    Let The Impossible Happen!!!

Similar Threads

  1. i want to read form URL
    By buffon2009 in forum Mobile Java General
    Replies: 2
    Last Post: 2011-01-19, 16:44
  2. Read from a URL
    By jaddeuel in forum Mobile Java Networking & Messaging & Security
    Replies: 4
    Last Post: 2010-06-05, 10:01
  3. J2ME Form and URL
    By qasimahmad in forum Mobile Java General
    Replies: 3
    Last Post: 2008-02-05, 08:21
  4. Replies: 1
    Last Post: 2003-05-22, 14:52
  5. my phone only display english, how to read chinese font SMS ?
    By hakenshizuo in forum General Development Questions
    Replies: 0
    Last Post: 2003-05-21, 07:31

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×