i am working on a JExplorer using swing. When i click a particular file, the appropriate application should be opened. For example, for filename.doc windows word application should be opened. This seems possible,if i access windows registry. please let me know whether any Java API is available for this or have i to go for JNI.

Torgeir Veimo

You will need a jni library, there is no standard java interface. There is a library called jnireg available at http://www.trustice.com/java/jnireg/ that does this.

Using this library, you can search for the contenttype (mimetype) given a file extension, and given the contenttype, you can search for the registered "handler".

The following code is from a friend of mine.

import com.ice.jni.registry.*;

public String getAppString(String fileext) throws Exception {
    String appString = "";

    RegistryKey skey = Registry.HKEY_CLASSES_ROOT;
    RegistryKey mkey = Registry.HKEY_CLASSES_ROOT;
    skey = skey.openSubKey(ext);
    String tt = skey.getDefaultValue();

    mkey = mkey.openSubKey(tt);
    mkey = mkey.openSubKey("shell");
    mkey = mkey.openSubKey("open");
    mkey = mkey.openSubKey("command");

    appString = mkey.getDefaultValue();

    appString = appString.replace('"',' ');
    StringTokenizer st = new StringTokenizer(appString);
    String sst;
    StringBuffer ret = new StringBuffer();
    ret.append(" ");
    while (st.hasMoreElements()) {
        sst = (String) st.nextElement();
        if ((sst.indexOf('%') == -1))
            ret.append(sst + " ");
    return ret.toString();