Skip to main content

Navigating the file system on a mobile device

John Muchow, Author
John Muchow is the author of Core J2ME Technology and MIDP, a popular J2ME book that has been translated into several foreign languages.

Summary:  This tutorial goes 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.

Date:  09 May 2005
Level:  Introductory PDF:  A4 and Letter (86 KB | 29 pages)Get Adobe® Reader®

Comments:  

Before you start

About this tutorial

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.


Software prerequisites

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.

Install the software

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.

1 of 8 | Next

Comments



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Java technology
ArticleID=136882
TutorialTitle=Navigating the file system on a mobile device
publish-date=05092005
author1-email=
author1-email-cc=

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).