当前位置: 技术问答>java相关
如何使用文件过滤器
来源: 互联网 发布时间:2015-04-04
本文导语: JFileChooser chooser = new JFileChooser(); ExampleFileFilter filter = new ExampleFileFilter(); filter.addExtension("jpg"); filter.addExtension("gif"); 编译却说"SeqAnalysisFrame.java": Error #: 300 : class ExampleFileFilter not found in cla...
JFileChooser chooser = new JFileChooser();
ExampleFileFilter filter = new ExampleFileFilter();
filter.addExtension("jpg");
filter.addExtension("gif");
编译却说"SeqAnalysisFrame.java": Error #: 300 : class ExampleFileFilter not found in class seqanalysis.SeqAnalysisFrame at line 36, column 3
是不是还要import什么库?
ExampleFileFilter filter = new ExampleFileFilter();
filter.addExtension("jpg");
filter.addExtension("gif");
编译却说"SeqAnalysisFrame.java": Error #: 300 : class ExampleFileFilter not found in class seqanalysis.SeqAnalysisFrame at line 36, column 3
是不是还要import什么库?
|
ExampleFileFilter是自己写的,而且是从FileFilter继承过来的
|
ExampleFileFilter需要自己编写,下面给出具体类代码的实现。
/**
*Class ExampleFileFilter supply specify file type to be
*selected.
*/
public class ExampleFileFilter extends javax.swing.filechooser.FileFilter
{
/**
*The type of file can be accepted.
*/
public boolean accept(java.io.File f)
{
boolean accept = f.isDirectory();
if (!accept)
{
String suffix = getSuffix(f);
if (suffix != null)
accept = suffix.equals("desc");
}
return accept;
}
/**
*Get the extends name of select file.
*/
public String getDescription()
{
return "Description Files (*.desc)";
}
/**
*Get suffix of select file.
*/
private String getSuffix(java.io.File f)
{
String s = f.getPath();
String suffix = null;
int i = s.lastIndexOf('.');
if (i > 0 && i
/**
*Class ExampleFileFilter supply specify file type to be
*selected.
*/
public class ExampleFileFilter extends javax.swing.filechooser.FileFilter
{
/**
*The type of file can be accepted.
*/
public boolean accept(java.io.File f)
{
boolean accept = f.isDirectory();
if (!accept)
{
String suffix = getSuffix(f);
if (suffix != null)
accept = suffix.equals("desc");
}
return accept;
}
/**
*Get the extends name of select file.
*/
public String getDescription()
{
return "Description Files (*.desc)";
}
/**
*Get suffix of select file.
*/
private String getSuffix(java.io.File f)
{
String s = f.getPath();
String suffix = null;
int i = s.lastIndexOf('.');
if (i > 0 && i