public class JFileChooserKnow
{ /**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
//文件选择器
JFileChooser chooser = new JFileChooser();
//设置文件过滤器
chooser.setFileFilter(new FileNameExtensionFilter("图片","gif","jpg","bmp"));
//获取用户的操作结果,是确认了,还是取消了
int choose = chooser.showOpenDialog(null);
//判断选择的结果
if(choose == JFileChooser.APPROVE_OPTION)
{
//获取文件路径
JOptionPane.showMessageDialog(null, chooser.getSelectedFile().getAbsolutePath());
}
} }