2014年3月6日 星期四

Java Applet 開啟本地資料夾

Java Applet 簡介與範例可以參照 Wiki
http://zh.wikipedia.org/wiki/Java_applet

import java.applet.Applet;
import java.io.File;
import java.io.IOException;

public class OpenExplorer extends Applet {
/**

*/
private static final long serialVersionUID = 1L;

public void init() {
        //Execute a job on the event-dispatching thread; creating this applet's GUI.
String url = getParameter("filepath").replace("file:", "").replaceAll("\\\\|/", "\\"+System.getProperty("file.separator"));
System.out.println(getParameter("filepath"));
File f = new File(url);
String command = "";
if(!f.isDirectory()) command = "/select,";

        try {
Process p = new ProcessBuilder("explorer.exe", command + url).start();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
        
    }

}

沒有留言:

張貼留言