11011110110011011001100110011001000110011001100111010001011

April 2, 2008

connections with cldc

Filed under: Programming
import java.io.*;
import javax.microedition.io.*;
	
public class TestInput {
	
    public static void main( String args[] ) {
        try {
            String uri = \"file:c:/autoexec.bat\";
            InputConnection conn = (InputConnection)
                     Connector.open( uri,
                        Connector.READ );
            InputStream in = conn.openInputStream();
            int ch;
	
            conn.close();  // doesn’t close input stream!
            while( ( ch = in.read() ) != -1 ){
                System.out.print( (char) ch );
            }
	
            in.close();
        }
        catch( ConnectionNotFoundException e ){
            System.out.println( “File could not be
                                         found!” );
        }
        catch( IOException e ){
        System.out.println( e.toString() );
        }
	
        System.exit( 0 );
    }
}

Notice that the program can safely close the connection after it obtains the input stream!!!
The input stream isn’t closed !! And the output stream either.

Comments »

The URI to TrackBack this entry is: http://lyo.blogsome.com/2008/04/02/connections-with-cldc/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.