Package javax.microedition.io.file

Examples of javax.microedition.io.file.FileConnection


    };

    public static void save() {
        System.out.println("saving...");
        try {
            FileConnection file =
                    (FileConnection) Connector.open("file:///root1/char.bin");
            try {
                if (!file.exists()) {
                    file.create();
                    file.truncate(0);
                }
                DataOutputStream out = file.openDataOutputStream();

                try {

                    System.out.println("saving X: " + X.length);
                    for (int i = 0; i <  X.length; i++) {
                        out.writeByte(X[i]);
                    }

                    System.out.println("saving Y: " + Y.length);
                    for (int i = 0; i < Y.length; i++) {
                        out.writeShort(Y[i]);
                    }

                    System.out.println("saving A: " + A.length);
                    for (int i = 0; i < A.length; i++) {
                        out.writeInt(A[i]);
                    }
                } finally {
                    out.close();
                }
            } finally {
                file.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
View Full Code Here


     * @return The image data
     */
    private byte[] getData(final String url) {
        byte[] data = new byte[0];
        try {
            final FileConnection file = (FileConnection) Connector.open(url);
            final int fileSize = (int) file.fileSize();
            data = new byte[fileSize];
            final InputStream inputStream = file.openInputStream();
            inputStream.read(data);
        } catch (final Exception e) {
            errorDialog(e.toString());
        }
        return data;
View Full Code Here

                    }

                    if (path != null) {
                        // Set the directory to open the FilePicker in if the
                        // directory exists.
                        final FileConnection fconn =
                                (FileConnection) Connector.open(path);
                        if (fconn.exists()) {
                            _filePicker.setPath(path);
                        }
                    }
                } catch (final Exception ioe) {
                    UiApplication.getUiApplication().invokeLater(
View Full Code Here

                _statusField
                        .setText("Open the menu to download or upload attachments");

                // Check if SD card is inserted
                try {
                    final FileConnection fc =
                            (FileConnection) Connector.open("file:///SDCard/");
                    fc.close();
                    _app.pushScreen(new FileExplorerScreen(_app));
                } catch (final IOException e) {
                    Dialog.inform("Please insert an SD card to upload items.");
                }
            }
View Full Code Here

        _model.removeAllRows();

        Enumeration rootEnum = null;

        if (root != null) {
            FileConnection fc = 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) {
                AttachmentDemo.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) {
                    }
                }
            }
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);

            // Create a file holder from the FileConnection so that the
            // connection is not left open
            final FileHolder fileholder =
                    new FileHolder(file, fc.isDirectory());
            _model.addRow(fileholder);
        } catch (final IOException e) {
            System.out.println("Connector.open(" + file + ") threw "
                    + e.toString());
        } finally {
            if (fc != null) {
                // Everything is read. Close the connection.
                try {
                    fc.close();
                    fc = null;
                } catch (final Exception ioex) {
                }
            }
        }
View Full Code Here

            final String fileSystemName = (String) fileSystemList.nextElement();

            // Cannot write data to "system/" partition
            if (!fileSystemName.equals("system/")) {
                try {
                    final FileConnection fconn =
                            (FileConnection) Connector.open("file:///"
                                    + fileSystemName);
                    if (fconn.availableSize() >= minSize) {
                        fileSystems.addElement(fileSystemName);
                    }
                } catch (final IOException e) {
                    // If an exception occurs, just ignore the file system
                }
View Full Code Here

     *            A locator string in URI syntax that points to the video file
     */
    public VideoPlaybackScreen(final String file) {
        boolean notEmpty;
        try {
            final FileConnection fconn = (FileConnection) Connector.open(file);
            notEmpty = fconn.exists() && fconn.fileSize() > 0;
            fconn.close();
        } catch (final IOException e) {
            Dialog.alert("Exception while accessing the video filesize:\n\n"
                    + e);
            notEmpty = false;
        }
View Full Code Here

     *            If false, search for "pictures" folder, if true then search
     *            for pictures within folder.
     */
    private void
            readDirectory(final String root, final boolean isPictureFolder) {
        FileConnection fc = null;

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

            if (fc.isDirectory()) {
                final Enumeration e = fc.list();
                while (e.hasMoreElements()) {
                    final String inner = (String) e.nextElement();

                    if (isPictureFolder) {
                        _pictureFileNames.addElement(inner);
View Full Code Here

     *            Path to the resource to be read
     * @return byte[] A byte array containing the specified resource
     */
    private byte[] readStream(final String path) {
        InputStream in = null;
        FileConnection fc = null;
        byte[] bytes = null;

        try {
            fc = (FileConnection) Connector.open(path);
            if (fc != null && fc.exists()) {
                in = fc.openInputStream();
                if (in != null) {
                    bytes = IOUtilities.streamToBytes(in);
                }
            }
        } catch (final IOException e) {
            AttachmentDemo.errorDialog(e.toString());
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (final IOException e) {
            }
            try {
                if (fc != null) {
                    fc.close();
                }
            } catch (final IOException e) {
            }

        }
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.