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

Page 24
Image 24
Motorola i88s manual Example # 2 Complete MIDlet code