Question

I am using Netbeans IDE (J2ME) for developing a mobile application, a dictionary which retrieve the meaning of the word when user enter a word.

How can I save/retrieve these meanings in the application (in the .jar file) any database? any method? And I have to distribute this application.

Était-ce utile?

La solution

With java-me you have support of Record Management System (RMS), You could store little data there,

The nice way would be store little information and when user queries the word see if it is there in local RMS , provide it, Otherwise you make a webservice call to your server and provide the information to user

Autres conseils

A dictionary is a key/value data structure, just like a Hashtable. You can store your data on jar file as a Java properties file (http://docs.oracle.com/javase/tutorial/essential/environment/properties.html).

As Java ME does not have the java.util.Properties class you have to do the loading manually.

    public class Properties extends Hashtable {

        public Properties(InputStream in) throws IOException {
            if (in == null) {
                throw new IllegalArgumentException("in == null");
            }

            StringBuffer line = new StringBuffer();

            while (readLine(in, line)) {
                String s = line.toString().trim();

                if (s.startsWith("#") == false) {
                    int i = s.indexOf('=');

                    if (i > 0) {
                        String key = s.substring(0, i).trim();
                        String value = s.substring(i + 1).trim();

                        put(key, value);
                    }
                }
                line.setLength(0);
            }
        }

        private boolean readLine(InputStream in, StringBuffer line) throws IOException {
            int c = in.read();

            while (c != -1 && c != '\n') {
                line.append((char)c);
                c = in.read();
            }

            return c >= 0 || line.length() > 0;
        }

        public String get(String key) {
            return (String) super.get(key);
        }
    }

Here is a sample

    InputStream is = getClass().getResourceAsStream("/dictionary.properties");
    Properties dictionary = new Properties(is);

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top