Motorola i88s manual Sc.close

Page 27

Motorola Inc.

i88s J2ME Developers’ Guide

 

sc.close();

 

}

 

catch(Exception ex) {

 

}

}

 

}

 

private

void deleteFile() {

try

{

 

//open a file in the delete mode

//by doing this existing file is eventually delete sc =

(StreamConnection)Connector.open("file://"+"fileURL"+";"+"DELETE"); //close the stream

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

myOutput.append("file deleted"); }catch (Exception ex1 ) {

System.out.println("Exception: " + ex1.getMessage()); try{

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

}

catch(Exception ex) {

}

}

}

}

3.5Tips

These are five basic steps to communicating with a file:

1.Open the file using the Connector.open() method of Connector class. This returns a StreamConnection object for file. Otherwise, an IOException is thrown.

2.Get the output stream using the openOutputStream() method of OutputConnection.

3.Get the input stream using the openInputStream() method of InputConnection.

4.Read and write data onto those streams.

5.Close the file using the close() method of Connection.

Once the connection has been established, simply use the normal methods of any input or output stream to read and write data.

File I/O is a simple alternative to Record Management System (RMS). When used effectively, direct File I/O can speed up storing and retrieving data.

After creating a file from a MIDlet suite, the file is associated with the current MIDlet suite only. No other MIDlet suite can access it.

Version 1.0 - Page 27

Image 27
Contents I88s Multi-Communication Device J2ME Developers’ Guide J2ME Networking Disclaimer Document OverviewContact Information Acronyms and DefinitionsAcronyms Used In This Guide Terminology Definition Overview Agps On The i88s PhonePosition API AccuracyAssist Data PositionConnection Class Almanac Out Of DateExample GetPositionString name Method DescriptionsRetrieving Position in Java GetPositionGetStatus Using Position in JavaExample Using PositionConnection Positionresponsenoalmanacoverride Addition, to obtain better accurate speed and direction Recommendation Http Https J2ME NetworkingClass Descriptions Http HttpsSupported Protocols on the i88s Phone TCP Sockets SSL Secure SocketsServerSockets UDP Sockets Serial Port AccessCommunicating on a Port Connection Optional ParametersImplementation Notes Example using StreamConnectionConcurrent Connections For The i88s Phone Protocol Maximum TipsFile 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