Before you start
The Java™ 2 Platform, Micro Edition (J2ME) Mobile Device Information Profile (MIDP) does not provide out-of-the-box support for accessing a file system. The optional package that provides this capability is defined by Java Specification Request (JSR) 75. Two packages are included in JSR 75: the Personal Information Management (PIM) package and the FileConnection package. This tutorial focuses on the FileConnection package, with an emphasis on learning how to navigate a directory tree and access files.
This tutorial takes you through the steps to build a simple file and directory explorer application. It includes moving through a directory hierarchy, viewing file permissions, and opening and reading a file's contents.
This tutorial begins by having you download and install the necessary software. It takes you through becoming familiar with the FileConnection API, including how to verify that the API is available on a device. Then, you'll create a simple file system on your development machine for testing the MIDlet's you will write as you progress through the tutorial. This entails configuring both the Wireless Toolkit (WTK), as well as building a file hierarchy on your hard drive.
Next, you'll write a MIDlet that navigates the custom file system. This same MIDlet will also provide support for viewing the attributes of any files you encounter in the hierarchy. Finally, you'll build upon the previous MIDlet, extending the application to open, read, and display file contents.
You'll start by downloading and installing the necessary software.
You'll need two software tools to complete this tutorial:
-
The Java Development Kit (JDK): You need to download and install the JDK. The development kit will allow the applications to compile and package the J2ME code. Download version 1.4 or greater. Download JDK version 1.4.2.
- The Wireless Toolkit (WTK): The Sun Microsystems Wireless Toolkit is the integrated tool in this tutorial for building MIDlets. The tool includes basic project support, as well as compiling, building, packaging, and running of J2ME applications. Download J2ME Wireless Toolkit 2.2.
The Java Development Kit (JDK)
Use the JDK documentation to install the JDK. You can choose either the default directory or specify another directory. If you choose to specify a directory, make a note of where you install the JDK. During the installation process for the Wireless Toolkit, the software attempts to locate the Java Virtual Machine (JVM); if it cannot locate the JVM, you are prompted for the JDK installation path.
The Wireless Toolkit (WTK)
If you are new to the WTK, you might be interested in the developerWorks tutorial "MIDlet Development with the Wireless Toolkit" (see Resources), which explains the basics of creating MIDlets with the toolkit. This tutorial is an excellent starting point if you are new to the Wireless Toolkit.
The Wireless Toolkit is contained within a single executable file. Run this file to begin the installation process. It is recommended that you use the default installation directory. However, if you do not use the default directory, make sure the path you select does not include any spaces.
