Motorola i88s manual Example # 2 Complete MIDlet code

Page 24

Motorola Inc.

i88s J2ME Developers’ Guide

is.read(b1); } finally {

if (sc != null) sc.close(); if (is != null) is.close();

if (os != null) os.close();

}

Example # 2 (Complete MIDlet code)

The following example is a simple MIDlet that will provide the overall operation of the file I/O interface and how most of the API’s can be used. The MIDlet also shows a simple alternative to RMS to store data as a persistent storage.

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

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

public class Example2 extends MIDlet implements CommandListener{ /**

*List of available tests

*/

StreamConnection sc;

String[] testList = {"file to w/r","setData","write/append/read","delete"}; TextBox tf1;

TextBox tf2; /**

*Reference to Display object associated with this Display

*/

Display myDisplay;

/* default file name */ String fileURL = "temp.txt"; /*default amount of data*/ int dataNum = 0;

/*default string to write in file*/ String stringNum ="Hello World"; /**

*The output screen

*/

Form myOutput; /**

*The list of tests

*/

List myList; /**

*Ok command to indicate a test was selected

*/

Command okCommand; /**

*Create NetTests

*/

Example2( ) {

}

Version 1.0 - Page 24

Image 24
Contents I88s Multi-Communication Device J2ME Developers’ Guide J2ME Networking Document Overview DisclaimerContact Information Acronyms and DefinitionsAcronyms Used In This Guide Terminology Definition Agps On The i88s Phone OverviewPosition API AccuracyAssist Data PositionConnection Class Almanac Out Of DateExample Method Descriptions Retrieving Position in JavaGetPosition GetPositionString nameUsing Position in Java GetStatusExample Using PositionConnection Positionresponsenoalmanacoverride Addition, to obtain better accurate speed and direction Recommendation J2ME Networking Http HttpsClass Descriptions Http HttpsSupported Protocols on the i88s Phone TCP Sockets SSL Secure SocketsServerSockets Serial Port Access UDP SocketsConnection Optional Parameters Communicating on a PortExample using StreamConnection Implementation NotesTips Concurrent Connections For The i88s Phone Protocol MaximumFile I/O Class DescriptionMethod Descriptions Opening a file Deleting a file Reading and WritingCode Examples Example # 2 Complete MIDlet code Motorola Inc I88s J2ME Developers’ Guide Os = sc.openOutputStream //get InputStream Sc.close Caveats Motorola Inc I88s J2ME Developers’ Guide
Related manuals
Manual 43 pages 17.94 Kb