文件已在 src下面 为什么说File 异常啊???无解啊
import java.awt.BorderLayout;
import java.awt.Desktop;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.net.URI;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class ExampleFrame_13 extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
public static void main(String[] args) {
ExampleFrame_13 frame = new ExampleFrame_13();
frame.setVisible(true);
}
public ExampleFrame_13() {
super();
setTitle("使用桌面集成控件");
setBounds(100, 100, 500, 375);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JPanel panel = new JPanel();
getContentPane().add(panel, BorderLayout.NORTH);
final JButton dickButton = new JButton();
dickButton.setText("打开编程词典网");
dickButton.addActionListener(new ButtonListener(1));
panel.add(dickButton);
final JButton noteButton = new JButton();
noteButton.setText("打开记事本");
noteButton.addActionListener(new ButtonListener(2));
panel.add(noteButton);
final JButton docButton = new JButton();
docButton.setText("打开word文档");
docButton.addActionListener(new ButtonListener(0));
panel.add(docButton);
}
private class ButtonListener implements ActionListener {
int index;
public ButtonListener(int index) {
this.index = index;
}
public void actionPerformed(ActionEvent e) {
try{
if (Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop();
switch (index) {
case 1:
if (desktop.isSupported(Desktop.Action.BROWSE)) {
desktop.browse(new URI(
"http://www.mrbccd.com"));
break;
}
case 2:
if (desktop.isSupported(Desktop.Action.EDIT)) {
desktop.edit(new File("src/new.txt"));
break;
}
default:
if (desktop.isSupported(Desktop.Action.OPEN)) {
desktop.open(new File("src/new.doc"));
}
}
}
}catch(Exception e1){
e1.printStackTrace();
}
}
}
}