Package javax.microedition.io.file

Examples of javax.microedition.io.file.FileConnection


            e = dir.list();

        while (e.hasMoreElements()) {
            String p = path + (String) e.nextElement();

            FileConnection fc = (FileConnection) Connector.open(
                    "file://localhost/" + p);
            if (fc.isDirectory())
                addDir(p, fc, topDir);
            else {
                addProblems(p, topDir, fc.openInputStream(), false);
            }
            fc.close();
        }
    }
View Full Code Here


        wc.setProgress(0);
        display.setCurrent(wc);

        try {
            Enumeration e;
            FileConnection currDir = null;
            List browser = createBrowser();

            if (MEGA_ROOT.equals(currDirName)) {
                e = FileSystemRegistry.listRoots();
            } else {
                currDir = (FileConnection) Connector.open("file://localhost/"
                        + currDirName);
                e = currDir.list();
                // not root - draw UP_DIRECTORY
                browser.append(UP_DIRECTORY, dirIcon);
            }

            while (e.hasMoreElements()) {
                String fileName = (String) e.nextElement();
                if (fileName.charAt(fileName.length() - 1) == FilePath.separatorChar)
                    browser.append(fileName, dirIcon);
                else if (fileName.toLowerCase().endsWith(".sgf"))
                    browser.append(fileName, sgfFileIcon);
                else if (fileName.toLowerCase().endsWith(".sgfi"))
                    browser.append(fileName, sgfiFileIcon);
                else
                    browser.append(fileName, fileIcon);
            }

            if (currDir != null)
                currDir.close();

            display.setCurrent(browser);
        } catch (IOException e) {
            //#if debug
            e.printStackTrace();
View Full Code Here

    void showProperties(String fileName) {
        try {
            if (fileName.equals(UP_DIRECTORY))
                return;

            FileConnection fc = (FileConnection) Connector.open("file://localhost/" + currDirName + fileName);
            if (!fc.exists())
                throw new IOException(T._("File does not exists."));

            Form props = new Form(T._("Properties") + ": " + fileName);
            props.addCommand(backToBCommand);
            props.setCommandListener(this);

            props.append(new StringItem(T._("Location"), currDirName));
            props.append(new StringItem(T._("Type"), fc.isDirectory() ? T._("Directory") : T._("Regular File")));
            props.append(new StringItem(T._("Size"), Long.toString((fc.isDirectory() ? fc.directorySize(true) : fc.fileSize()))));
            props.append(new StringItem(T._("Modified"), myDate(fc.lastModified())));

            ChoiceGroup attrs = new ChoiceGroup(T._("Attributes"), Choice.MULTIPLE, attrList, null);
            attrs.setSelectedFlags(new boolean[] { fc.canRead(), fc.canWrite(), fc.isHidden() });
            props.append(attrs);

            if (fileName.toLowerCase().endsWith(".sgf"))
                try {
                    StringBuffer sb = new StringBuffer();
                    InputStream is = fc.openInputStream();
                    InputStreamReader isr = new InputStreamReader(is);
                    SGFParser parser = new SGFParser(isr);
                    SGFNode head = parser.parseHead();
                    is.close();
                    for (Enumeration e = head.getProperties(); e.hasMoreElements(); ) {
                        sb.append(e.nextElement().toString());
                        sb.append("\n");
                    }
                    props.append(new StringItem(T._("SGF Header"), sb.toString()));
                } catch (Exception e) {
                }

            fc.close();
            display.setCurrent(props);
        } catch (Exception e) {
            Alert alert = new Alert(T._("Error!"), T._("Can't access file ") + fileName
                    + T._(" in directory ") + currDirName + "\n" + T._("Exception: ")
                    + e.getMessage(), null, AlertType.ERROR);
View Full Code Here

        }
    }

    void deleteFile(String fileName) {
        try {
            FileConnection fc = (FileConnection) Connector.open("file:///"
                    + currDirName + fileName);
            fc.delete();
        } catch (Exception e) {
            Alert alert = new Alert(T._("Error!"), T._("Can not access/delete file ")
                    + fileName + T._(" in directory ") + currDirName + "\n"
                    + T._("Exception: ") + e.getMessage(), null, AlertType.ERROR);
            alert.setTimeout(Alert.FOREVER);
View Full Code Here

        }).start();
    }

    private void checkDeleteFolder(String folderName) {
        try {
            FileConnection fcdir = (FileConnection) Connector
                    .open("file://localhost/" + currDirName + folderName);
            Enumeration content = fcdir.list("*", true);
            // only empty directory can be deleted
            if (!content.hasMoreElements()) {
                fcdir.delete();
                showCurrDir();
            } else {
                Alert cantDeleteFolder = new Alert(T._("Error!"),
                        T._("Can not delete The non-empty folder: ") + folderName,
                        null, AlertType.ERROR);
View Full Code Here

        display.setCurrent(creator);
    }

    void createFile(String newName, boolean isDirectory) {
        try {
            FileConnection fc = (FileConnection) Connector.open("file://localhost/"
                    + currDirName + newName);
            if (isDirectory) {
                fc.mkdir();
            } else {
                fc.create();
            }
            fc.close();
            showCurrDir();
        } catch (Exception e) {
            String s = T._("Can not create file ") + newName;
            if (e.getMessage() != null && e.getMessage().length() > 0) {
                s += "\n" + e;
View Full Code Here

        wc.setProgress(0);
        display.setCurrent(wc);

        try {
            Enumeration e;
            FileConnection currDir = null;
            List browser = createBrowser();

            if (MEGA_ROOT.equals(currDirName)) {
                e = FileSystemRegistry.listRoots();
            } else {
                currDir = (FileConnection) Connector.open("file://localhost/"
                        + currDirName);
                e = currDir.list();
                // not root - draw UP_DIRECTORY
                browser.append(UP_DIRECTORY, dirIcon);
            }

            while (e.hasMoreElements()) {
                String fileName = (String) e.nextElement();
                if (fileName.charAt(fileName.length() - 1) == FilePath.separatorChar)
                    browser.append(fileName, dirIcon);
                else if (fileName.toLowerCase().endsWith(".sgf"))
                    browser.append(fileName, sgfFileIcon);
                else if (fileName.toLowerCase().endsWith(".sgfi"))
                    browser.append(fileName, sgfiFileIcon);
                else
                    browser.append(fileName, fileIcon);
            }

            if (currDir != null)
                currDir.close();

            display.setCurrent(browser);
        } catch (IOException e) {
            //#if debug
            e.printStackTrace();
View Full Code Here

    void showProperties(String fileName) {
        try {
            if (fileName.equals(UP_DIRECTORY))
                return;

            FileConnection fc = (FileConnection) Connector.open("file://localhost/" + currDirName + fileName);
            if (!fc.exists())
                throw new IOException(T._("File does not exists."));

            Form props = new Form(T._("Properties") + ": " + fileName);
            props.addCommand(backToBCommand);
            props.setCommandListener(this);

            props.append(new StringItem(T._("Location"), currDirName));
            props.append(new StringItem(T._("Type"), fc.isDirectory() ? T._("Directory") : T._("Regular File")));
            props.append(new StringItem(T._("Size"), Long.toString((fc.isDirectory() ? fc.directorySize(true) : fc.fileSize()))));
            props.append(new StringItem(T._("Modified"), myDate(fc.lastModified())));

            ChoiceGroup attrs = new ChoiceGroup(T._("Attributes"), Choice.MULTIPLE, attrList, null);
            attrs.setSelectedFlags(new boolean[] { fc.canRead(), fc.canWrite(), fc.isHidden() });
            props.append(attrs);

            if (fileName.toLowerCase().endsWith(".sgf"))
                try {
                    StringBuffer sb = new StringBuffer();
                    InputStream is = fc.openInputStream();
                    InputStreamReader isr = new InputStreamReader(is);
                    SGFParser parser = new SGFParser(isr);
                    SGFNode head = parser.parseHead();
                    is.close();
                    for (Enumeration e = head.getProperties(); e.hasMoreElements(); ) {
                        sb.append(e.nextElement().toString());
                        sb.append("\n");
                    }
                    props.append(new StringItem(T._("SGF Header"), sb.toString()));
                } catch (Exception e) {
                }

            fc.close();
            display.setCurrent(props);
        } catch (Exception e) {
            Alert alert = new Alert(T._("Error!"), T._("Can't access file ") + fileName
                    + T._(" in directory ") + currDirName + "\n" + T._("Exception: ")
                    + e.getMessage(), null, AlertType.ERROR);
View Full Code Here

        }
    }

    void deleteFile(String fileName) {
        try {
            FileConnection fc = (FileConnection) Connector.open("file:///"
                    + currDirName + fileName);
            fc.delete();
        } catch (Exception e) {
            Alert alert = new Alert(T._("Error!"), T._("Can not access/delete file ")
                    + fileName + T._(" in directory ") + currDirName + "\n"
                    + T._("Exception: ") + e.getMessage(), null, AlertType.ERROR);
            alert.setTimeout(Alert.FOREVER);
View Full Code Here

        }).start();
    }

    private void checkDeleteFolder(String folderName) {
        try {
            FileConnection fcdir = (FileConnection) Connector
                    .open("file://localhost/" + currDirName + folderName);
            Enumeration content = fcdir.list("*", true);
            // only empty directory can be deleted
            if (!content.hasMoreElements()) {
                fcdir.delete();
                showCurrDir();
            } else {
                Alert cantDeleteFolder = new Alert(T._("Error!"),
                        T._("Can not delete The non-empty folder: ") + folderName,
                        null, AlertType.ERROR);
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.