Motorola i88s manual File I/O, Class Description, Method Descriptions Opening a file

Page 22
Version 1.0 - Page 22
Connector.READ_WRITE

Motorola Inc.

i88s J2ME Developers’ Guide

3 File I/O

3.1Overview

The objective of the File I/O API is to provide a generic platform for the Java developer to use to open, read, and/or write, append and delete a file sequentially. The goal is to provide UNIX like file access APIs, as a simple alternative to Record Management System (RMS).

Almost all MIDlets need to be able to save information to be retained between invocations; this is called “persistent storage.”

Examples include:

-Saving data such as notes, phone numbers, tasks, etc…

-Keeping a history of recent URLs

3.2Class Description

import javax.microedition.io.Connector

3.3Method Descriptions

3.3.1Opening a file

Opening a file gives your application exclusive access to that particular file until it is explicitly closed or the program is ended.

To open a file, a J2ME application can use all the APIs defined by the Connector class.

StreamConnection sc =(StreamConnection)Connector.open(String name) throws java.io.IOException

Argument name is the name of the file to open, and can include the mode in which to open the file

e.g. name = “file://temp.txt” specifies that file is to be opened in the default mode, READ_WRITE or name = “file://temp.txt;APPEND” which specifies that file is to be opened in an APPEND mode.

StreamConnection sc =(StreamConnection)Connector.open(String name, int mode);

name = “file://temp.txt” and mode may have three values: Connector.READ,

Connector.WRITE, and.

Image 22
Contents I88s Multi-Communication Device J2ME Developers’ Guide J2ME Networking Document Overview DisclaimerAcronyms and Definitions Contact InformationAcronyms Used In This Guide Terminology Definition Agps On The i88s Phone OverviewAccuracy Position APIAssist Data Almanac Out Of Date PositionConnection ClassExample 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 Https HttpSupported Protocols on the i88s Phone SSL Secure Sockets TCP SocketsServerSockets Serial Port Access UDP Sockets Connection Optional Parameters Communicating on a PortExample using StreamConnection Implementation NotesTips Concurrent Connections For The i88s Phone Protocol MaximumClass Description File I/OMethod Descriptions Opening a file Reading and Writing Deleting a fileCode 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