日期:2014-05-17  浏览次数:20706 次

如何实现上传文件时浏览只显示与类型匹配的文件
在上传文件的时候如何再点击浏览按钮后 只显示EXCLE文件和文件夹 其他不显示

------解决方案--------------------
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Text Document(*.txt)|*.txt|All Files|*.*|我要显示的文件类型(*.exe)|*.exe";//设置文件过滤器用于打开文件对话框中显示特定类型的文件
ofd.ShowDialog();
或者
 JFileChooser chooser = new JFileChooser(new File("c:\\"));

chooser.setFileFilter(new FileFilter() {
public String getDescription()
{
// TODO Auto-generated method stub
return null;
}
public boolean accept(File f)
{
// TODO Auto-generated method stub
if(f.isDirectory())return true;
else
return f.getName().endsWith(".gif");
}
});

chooser.showOpenDialog(null);
这个只显示gif,当然其他类型可以自己控制