Motorola i88s manual Os = sc.openOutputStream //get InputStream

Page 26

Motorola Inc.

i88s J2ME Developers’ Guide

readWrite();

break;

case 3: myDisplay.setCurrent(myOutput);

deleteFile();

break;

}

}else { myDisplay.setCurrent(myList);

}

}

private void setFileName() { myDisplay.setCurrent(tf1);

}

private void setData() { myDisplay.setCurrent(tf2);

}

private void readWrite() { int length = dataNum;

byte[] message = new byte[length]; message = stringNum.getBytes();

OutputStream os = null; InputStream is = null; try {

//open a file in the mode APPEND sc =

(StreamConnection)Connector.open("file://"+"fileURL"+";"+"APPEND"); //get OutputStream

os = sc.openOutputStream(); //get InputStream

is = sc.openInputStream(); //write the bytes to the file os.write(message); myOutput.append("write/append done");

//create an array to store available data from the file byte [ ] b1 = new byte[is.available()];

//read the bytes is.read(b1);

String readString = new String(b1); //printout the data in the phone screen myOutput.append(readString); myOutput.append("read finished"); //close all the opened streams

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

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

} catch (Exception e) { System.out.println("Exception: " + e.getMessage()); try {

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

if (sc != null)

Version 1.0 - Page 26

Image 26
Contents I88s Multi-Communication Device J2ME Developers’ Guide J2ME Networking Document Overview DisclaimerAcronyms Used In This Guide Terminology Definition Contact InformationAcronyms and Definitions Agps On The i88s Phone OverviewAssist Data Position APIAccuracy Example PositionConnection ClassAlmanac Out Of Date GetPosition Method DescriptionsRetrieving Position in Java GetPositionString nameUsing Position in Java GetStatusExample Using PositionConnection Positionresponsenoalmanacoverride Addition, to obtain better accurate speed and direction Recommendation J2ME Networking Http HttpsClass Descriptions Supported Protocols on the i88s Phone HttpHttps ServerSockets TCP SocketsSSL Secure Sockets Serial Port Access UDP SocketsConnection Optional Parameters Communicating on a PortExample using StreamConnection Implementation NotesTips Concurrent Connections For The i88s Phone Protocol MaximumMethod Descriptions Opening a file File I/OClass Description Code Examples Deleting a file Reading and Writing 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