直接打开文件

来源:百度知道 编辑:UC知道 时间:2024/05/19 10:56:13
JEditorPane jEditorPane = new JEditorPane();
jEditorPane.setEditable(false);
jEditorPane.setContentType("text/html");
jEditorPane.setText("<html><body><a href=http://www.baidu.com>baidu</a></body></html>");
jEditorPane.addHyperlinkListener(new HyperlinkListener() {

public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
try {
String command = "explorer.exe "
+ e.getURL().toString();
Runtime.getRuntime().exec(command);
} catch (Exception ex) {
ex.printStackTrace();
System.err.println("connection error");
}
}
}
});
这是打开百度的
我已经做了个笔记本,希望在旁边做个连接
如何实现点击后直接打开本地文件

然后直接在要加链接的地方加入
.addHyperlinkListener(new HyperlinkListener() {

public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
try {
String command = "explorer.exe "
+ e.getURL().toString();
Runtime.getRuntime().exec(command);
} catch (Exception ex) {
ex.printStackTrace();
System.err.println("connection error");
}
}
}
}