1 import javax.swing.JFileChooser; 2 import org.eclipse.swt.internal.win32.TCHITTESTINFO; 3 4 public class test { 5 6 public static void main(String[] args) { 7 JFileChooser f = new JFileChooser(); 8 int result = f.showOpenDialog(null);//执行文件选择窗口 9 if (result==f.APPROVE_OPTION) { 10 String string = f.getSelectedFile().getPath();//得到文件路径 11 System.out.println(string); 12 } 13 if (result==f.CANCEL_OPTION) { 14 System.out.println("cancel"); 15 } 16 if (result == f.ERROR_OPTION) { 17 System.out.println("error"); 18 } 19 } 20 21 }