NetTest.java



import java.io.*;
import javax.microedition.io.*;
import com.nttdocomo.io.*;
import com.nttdocomo.ui.*;
public class NetTest extends IApplication
                     implements ComponentListener {

    public Panel panel;
    public Ticker ticker;
    public Button button;

    public void start() {
        panel = new Panel();
        panel.setTitle( "Network Test" );
        panel.setComponentListener( this );
        ticker = new Ticker();
        panel.add( ticker );
        button = new Button( "receive" );
        button.setForeground(
            Graphics.getColorOfRGB( 255, 128, 0 ) );
        panel.add( button );
        Display.setCurrent( panel );
    }

    public void componentAction( Component source, int type, int parm ) {

        if( source == button ) {
            String message = getMessage();
            ticker.setText( message );
        }
    }

    public String getMessage() {

        String message = null;
        try {
            HttpConnection connection
               = (HttpConnection)Connector.open(
                   "http://www.wakhok.ac.jp/~tatsuo/i/j/test.txt",
                    Connector.READ, true );
            connection.setRequestMethod( HttpConnection.GET );
            connection.setRequestProperty( "Content-Type", "text/plain" );
            connection.connect();
            InputStream in = connection.openInputStream();
            InputStreamReader reader = new InputStreamReader( in );
            StringBuffer sb = new StringBuffer();
            int i=0;
            while( ( i = reader.read() ) != -1 ) {
                 char c = ( char )i;
                 sb.append( c );
            }
            reader.close();
            in.close();
            connection.close();
            message = sb.toString();
        }
        catch( Exception e ) {
            System.err.println( e.toString() );
        }
        return message;
    }
}