Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Access URL 
 

This example is used to access the data from the specific url. The Stream Connection is used to connect the application to the specific url by Airtime (connect to the internet).

 

Access URL

                         

This example is used to access the data from the specific url. The Stream Connection is used to connect the application to the specific url by Airtime (connect to the internet). In this example we are trying to make a connection between internet and mobile. In the example we have created the connection, but here a message will be shown "Is it OK to Use Airtime?", If user click on 'No' button then it return to launch page, but if user click on 'Yes' button then it check the http connection from the internet, if connection is available then text will be displayed otherwise exception will be thrown.

 

 

 

 

The Application is as follows:

 

Source Code of AccessUrl.java

import java.io.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class AccessUrl extends MIDlet{
  private Display display;
  String url = "http://www.roseindia.net/hello.txt";

  public AccessUrl(){
    display = Display.getDisplay(this);
  }

  public void startApp(){
    try{
      connection(url);
    catch (IOException e){
      System.out.println("IOException " + e);
      e.printStackTrace();
    }
  }
  
  public void pauseApp(){}

  public void destroyApp(boolean unconditional){}

  void connection(String url) throws IOException{
    StreamConnection sc = null;
    InputStream is = null;
    StringBuffer buffer = new StringBuffer();
    TextBox access;
    try{
      sc = (StreamConnection)Connector.open(url);
      is = sc.openInputStream();
      int chars;
      while((chars = is.read()) != -1){
        buffer.append((char) chars);
      }
      System.out.println(buffer.toString());
      access = new TextBox("Access Text", buffer.toString(), 10240);
    }finally{
      if(is != null){
        is.close();
      }
      if(sc != null){
        sc.close();
      }
    }
    display.setCurrent(access);
  }
}

Download Source Code

                         

» View all related tutorials
Related Tags: c j2me diff types type if example to rectangle draw exam raw angle e il pe in different m nt

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.