Package javax.microedition.io.file

Examples of javax.microedition.io.file.FileConnection


                exceptions[dirURLIndex] = e;
                continue;
            }

            try {
                final FileConnection fcon = (FileConnection) con;
                if (!fcon.exists()) {
                    throw new IOException("directory does not exist");
                } else if (!fcon.isDirectory()) {
                    throw new IOException("not a directory");
                }

                for (int i = 0; i < SONG_FILENAMES.length; i++) {
                    final String filename = SONG_FILENAMES[i];
                    final String fileURL = fcon.getURL() + filename;

                    Connection con2;
                    try {
                        con2 = Connector.open(fileURL);
                    } catch (final Exception e) {
                        throw new IOException("unable to open connection to "
                                + fileURL + ": " + e);
                    }

                    try {
                        final FileConnection fcon2 = (FileConnection) con2;
                        if (fcon2.exists()) {
                            continue;
                        }

                        try {
                            fcon2.create();
                        } catch (final Exception e) {
                            throw new IOException("unable to create " + fileURL
                                    + ": " + e);
                        }
View Full Code Here


                        + dirURL + ": " + e);
                continue; // Skip this directory
            }

            try {
                final FileConnection fcon = (FileConnection) con;
                if (!fcon.isDirectory()) {
                    continue; // Not a directory, so skip it
                }

                // Search for files whose names end with ".mp3" and add them to
                // the playlist
                Enumeration enumeration;
                try {
                    enumeration = fcon.list();
                } catch (final Exception e) {
                    System.err.println("WARNING: unable to list files in "
                            + dirURL + ": " + e);
                    continue; // Skip this directory
                }

                while (enumeration.hasMoreElements()) {
                    final String filename = (String) enumeration.nextElement();
                    if (filename != null
                            && filename.toLowerCase().endsWith(".mp3")) {
                        final String fileURL = fcon.getURL() + filename;
                        final String name =
                                filename.substring(0, filename.length() - 4);
                        final PlaylistEntry playlistEntry =
                                new PlaylistEntry(fileURL, name);
                        vector.addElement(playlistEntry);
View Full Code Here

        if (fileholder != null) {
            final String filename =
                    fileholder.getPath() + fileholder.getFileName();

            if (Dialog.ask(Dialog.D_DELETE) == Dialog.DELETE) {
                FileConnection fc = null;

                try {
                    fc = (FileConnection) Connector.open("file:///" + filename);
                    fc.delete();
                    _model.removeRowAt(index);
                } catch (final Exception ex) {
                    FileExplorerDemo
                            .errorDialog("Unable to delete file or directory: "
                                    + filename);
                } finally {
                    try {
                        if (fc != null) {
                            fc.close();
                            fc = null;
                        }
                    } catch (final Exception ioex) {
                        FileExplorerDemo.errorDialog("deleteAction() threw "
                                + ioex.toString());
View Full Code Here

        // Clear list contents
        while (_model.getNumberOfRows() > 0) {
            _model.removeRowAt(0);
        }

        FileConnection fc = null;
        Enumeration rootEnum = null;

        if (root != null) {
            // Open the file system and get the list of directories/files
            try {
                fc =
                        (FileConnection) Connector.open("file:///" + root,
                                Connector.READ);
                rootEnum = fc.list();
            } catch (final Exception ioex) {
                FileExplorerDemo.errorDialog(ioex.toString());
            } finally {

                if (fc != null) {
                    // Everything is read, make sure to close the connection
                    try {
                        fc.close();
                        fc = null;
                    } catch (final Exception ioex) {
                        FileExplorerDemo.errorDialog("readRoots() threw "
                                + ioex.toString());
                    }
View Full Code Here

     *
     * @param file
     *            Upper directory to be read.
     */
    private void readSubroots(final String file) {
        FileConnection fc = null;

        try {
            fc =
                    (FileConnection) Connector.open("file:///" + file,
                            Connector.READ);

            // Create a file holder from the FileConnection so that the
            // connection is not left open
            final FileExplorerDemoFileHolder fileholder =
                    new FileExplorerDemoFileHolder(file);
            fileholder.setDirectory(fc.isDirectory());
            _model.addRow(fileholder);
        } catch (final Exception ioex) {
            FileExplorerDemo.errorDialog("Connector.open() threw "
                    + ioex.toString());
        } finally {
            if (fc != null) {
                // Everything is read, make sure to close the connection
                try {
                    fc.close();
                    fc = null;
                } catch (final Exception ioex) {
                    FileExplorerDemo.errorDialog("readSubRoots() threw "
                            + ioex.toString());
                }
View Full Code Here

                public void execute(final ReadOnlyCommandMetadata metadata,
                        final Object context) {
                    try {
                        // Create connection to a file that may or
                        // may not exist.
                        FileConnection file =
                                (FileConnection) Connector.open(FILE_NAME
                                        + _counter + EXTENSION);

                        // If the file exists, increment the counter and try
                        // again until we have a filename for a file that hasn't
                        // been created yet.
                        while (file.exists()) {
                            file.close();
                            ++_counter;
                            file =
                                    (FileConnection) Connector.open(FILE_NAME
                                            + _counter + EXTENSION);
                        }

                        // We know the file doesn't exist yet, so create it
                        file.create();

                        // Write the image to the file
                        final OutputStream out = file.openOutputStream();
                        out.write(_raw);

                        // Close the connections
                        out.close();
                        file.close();

                        // Inform the user where the file has been saved
                        Dialog.inform("Saved to " + FILE_NAME + _counter
                                + EXTENSION);
View Full Code Here

     * @param root
     *            The file path to be enumerated
     */
    private void enumerateDirectory(final String root) {
        if (root != null) {
            FileConnection fc = null;
            Enumeration rootEnum = null;

            // Open the file system and get the list of directories/files
            try {
                fc = (FileConnection) Connector.open(root);
                rootEnum = fc.list();
            } catch (final IOException e) {
                SendMenuDemo.errorDialog(e.toString());
                return;
            } finally {
                if (fc != null) {
                    // Everything is read, make sure to close the connection
                    try {
                        fc.close();
                        fc = null;
                    } catch (final IOException e) {
                    }
                }
            }

            if (rootEnum != null) {
                // Read through the list of directories/files
                while (rootEnum.hasMoreElements()) {
                    final String file = root + (String) rootEnum.nextElement();

                    try {
                        fc = (FileConnection) Connector.open(file);
                        if (!fc.isDirectory()) {
                            _model.addRow(file);
                        }
                    } catch (final IOException e) {
                        System.out.println("Connector.open(" + file
                                + ") threw " + e.toString());
                    }
                }

                if (fc != null) {
                    // Everything is read, close the connection.
                    try {
                        fc.close();
                        fc = null;
                    } catch (final Exception ioex) {
                    }
                }
            }
View Full Code Here

            // Close the database in case it is blank and we need to write to
            // the file
            db.close();

            // Open a connection to the database file
            final FileConnection fileConnection =
                    (FileConnection) Connector.open("file://" + dbLocation
                            + DB_NAME);

            // If the file is blank, copy the pre-defined database from this
            // module to the SDCard.
            if (fileConnection.exists() && fileConnection.fileSize() == 0) {
                readAndWriteDatabaseFile(fileConnection);
            }

            // Retrieve the code signing key for the XYZ key file
            final CodeSigningKey codeSigningKey =
View Full Code Here

  }

  protected void getFileList(String path) {
    try {
      // Opens a file connection in READ mode
      FileConnection fc = (FileConnection) Connector.open(path,
          Connector.READ);
      Enumeration filelist = fc.list("*", true); // also hidden files are
      String filename;
      while (filelist.hasMoreElements()) {
        filename = (String) filelist.nextElement();
        fc = (FileConnection) Connector.open(path + filename,
            Connector.READ);
        if (fc.isDirectory()) { // checks if fc is a directory
          this.getFileList(path + filename);
        } else {
          if (filename.endsWith(".mp3")) {
            this.append(filename + "\n");
            files.addElement(path + filename);
          }
        }
      }
      fc.close();
    } catch (IOException ioe) {
      System.out.println("IOException: " + ioe.getMessage());
    } catch (SecurityException se) {
      System.out.println("SecurityException: " + se.getMessage());
    }
View Full Code Here

    this.getFileList(title);
  }
  protected void getFileList(String path) {
        try {
            //Opens a file connection in READ mode
            FileConnection fc = (FileConnection)Connector.open(path, Connector.READ);
            Enumeration filelist = fc.list("*", true); //also hidden files are shown
            String filename;
            while(filelist.hasMoreElements()) {
                filename = (String) filelist.nextElement();
                fc = (FileConnection)Connector.open(path + filename, Connector.READ);
                if(fc.isDirectory()) { //checks if fc is a directory
                    this.append(filename, folderImage);
                } else if(filename.endsWith(".mp3")){ //otherwise, is a file
                    this.append(filename, mp3Image);
                } else if(filename.endsWith(".txt")){
                  this.append(filename, txtImage);
                }
            }  
            fc.close();
        }
        catch (IOException ioe) {
            System.out.println("IOException: "+ioe.getMessage());           
        }
        catch (SecurityException se) {
View Full Code Here

TOP

Related Classes of javax.microedition.io.file.FileConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.