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.

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