java-mejsr75

File connection+j2me


I want to make the application where I can get all the images no matter whether it is in phone or in external memory. I want to import all that images in my application. How can it be possible? I came to know that it is possible through file connection. But not getting exact idea.


Solution

    1. Get all the file system roots using FileSystemRegistry.listRoots()
    2. Open connection to each root in turn using FileConnection fconn = (FileConnection)Connector.open(root)
    3. List the folder using fconn.list().
    4. For each entry in the list, if it ends with an image extension (file.getName().endsWith(".png") etc), then it's an image.
    5. If the entry is a folder (file.isDirectory() returns true) then use fconn.setFileConnection(folder) to traverse into that directory/
    6. Do the same recursively for all folders in all roots.