Package javax.microedition.io.file

Examples of javax.microedition.io.file.FileConnection


        }
        return result;
    }

    public void saveFile(String fileName, byte[] data) throws IOException {
        final FileConnection conn = (FileConnection) Connector.open(rootPrefix + fileName);
        try {
            if (!conn.exists()) {
                conn.create();
            }
            final OutputStream out = conn.openOutputStream();
            try {
                out.write(data);
                out.flush();
            } finally {
                out.close();
            }
        } finally {
            conn.close();
        }
    }
View Full Code Here


                    if (Options.getInstance().useFileApi) {

                        Runnable saveFile = new Runnable() {
                            public void run() {
                                FileConnection fileConn;
                                try {
                                    fileConn = (FileConnection) Connector.open(fileUrl, Connector.READ_WRITE);

                                    if (!fileConn.exists()) {
                                        fileConn.create();
                                    }
                                    DataOutputStream outputStream = fileConn.openDataOutputStream();
                                    outputStream.write(imageData);
                                    outputStream.close();
                                    fileConn.close();
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                            }
                        };
View Full Code Here

        if (!options.useFileApi) {
            return;
        }
        String url = ("file:///" + options.rootName + dir);
        try {
            FileConnection conn = (FileConnection) Connector.open(url, Connector.READ_WRITE);
            if (!conn.exists()) {
                conn.mkdir();
            } else if (!conn.isDirectory()) {
                CloudGps.setError(url + " exists but is not a directory. Saving tiles will fail.");
            }
        } catch (IOException e) {
            CloudGps.setError(e);
        }
View Full Code Here

        int minute = cal.get(Calendar.MINUTE);
        int second = cal.get(Calendar.SECOND);
        String fileName = "GpsLog_" + cal.get(Calendar.YEAR) + "-" + prefixWithZero(month) + "-" + prefixWithZero(day)
                + "_" + prefixWithZero(hour) + "." + prefixWithZero(minute) + "." + prefixWithZero(second) + ".txt";
        try {
            FileConnection fileConn = (FileConnection) Connector.open("file:///" + Options.getInstance().rootName
                    + IOTool.NMEA_LOGS_DIR + "/" + fileName, Connector.WRITE);
            fileConn.create();
            return fileConn.openDataOutputStream();
        } catch (IOException e) {
            CloudGps.setError(e);
        }
        return null;
    }
View Full Code Here

    private static String prefixWithZero(int i) {
        return i < 10 ? "0" + i : "" + i;
    }

    public static String[] listDir(String dirUrl) throws IOException {
        FileConnection fileConn = (FileConnection) Connector.open(dirUrl, Connector.READ);
        Enumeration list = fileConn.list();
        Vector files = new Vector();

        while (list.hasMoreElements()) {
            files.addElement(list.nextElement());
        }
View Full Code Here

                int tries = 0;
                while (inputStream == null) {
                    try {
                        if (options.replayMode) {
                            inputStream = Connector.openInputStream(options.replayFileName);
                            FileConnection conn = (FileConnection) Connector.open(options.replayFileName,
                                    Connector.READ);
                            gpsState.replySize = conn.fileSize();
                            gpsState.replyPosition = 0;
                            conn.close();
                        } else {
                            inputStream = Connector.openInputStream(options.gpsUrl);
                        }
                    } catch (Throwable e) {
                        tries++;
View Full Code Here

     * @param path directory location
     */
    public void directoryWalk(String path) {
        files.removeAllElements();
        try {
            FileConnection fc = (FileConnection) Connector.open(path, Connector.READ);
            Enumeration fl = fc.list("*.jpg", true);
            while(fl.hasMoreElements()) {
                files.addElement((String) fl.nextElement());
            }
            fc.close();
        }
        catch (SecurityException e) {
            System.out.println("SecurityError: " + e.getMessage());
        }
        catch (IOException e) {
View Full Code Here

     *
     * @param fullPath The path of the file
     * @return <code>true</code> if the file exists; <code>false</code> otherwise
     */
    public static boolean exists( String fullPath ) {
        FileConnection con = open( fullPath );
        boolean retval = ( con != null && con.exists() && !con.isDirectory() );
        close( con );

        return retval;
    }
View Full Code Here

     * @param fullPath The path of the file
     * @return The properties of the file
     * @throws IOException if any error occurs during reading of the file
     */
    public static Hashtable getProperties( String fullPath ) throws IOException {
        FileConnection con = open( fullPath );
        if( con == null ) {
            throw new IOException( fullPath + " does not exist." );
        }

        String name = con.getName();
        String mimeType = MIMETypeAssociations.getMIMEType( name );

        int size = (int) con.fileSize();
        byte[] data = new byte[ size ];
        DataInputStream dis = con.openDataInputStream();
        dis.read( data, 0, size );
        close( dis );
        close( con );

        String encoding = getEncoding( data );
View Full Code Here

        if (newList != null) {
          displayFileList(newList);
          return;
        }
        String path = fileList.path + filename;
        FileConnection fc = (FileConnection) Connector.open("file:///" + path, Connector.READ);
        if (fc.isDirectory()) {
          newList = new FileList(filename, path, fileList, fc.list());
          fileList.sublists[index] = newList;
          displayFileList(newList);
          return;
        }
        InputStream is = fc.openInputStream();
        int module_len = 0;
        for (;;) {
          int i = is.read(module, module_len, ASAP.MODULE_MAX - module_len);
          if (i <= 0)
            break;
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.