📄 myfilefilter.java
字号:
package notepad.logic;
import java.io.File;
import javax.swing.filechooser.FileFilter;
/**
* 类名MyFileFilter<BR>
* 用于文件选择对话框中的文件筛选的类。<BR>
*
* @version 2.0 2009-4-27<BR>
*
* @author 黎明你好
*/
public class MyFileFilter extends FileFilter
{
/**保存文件的后缀名*/
private String postfix;
/**
* 类的构造方法
* @param string
* 需要过滤的文件后缀名
*/
public MyFileFilter(String string)
{
postfix = string;
}
/**
* 重写FileFilter的accept方法
*/
public boolean accept(File file)
{
if (file.isDirectory())
return true;
String fileName = file.getName();
int index = fileName.lastIndexOf('.');
if (index > 0 && index < fileName.length() - 1)
{
String extension = fileName.substring(index + 1).toLowerCase();
if (extension.equals(postfix))
return true;
}
return false;
}
public String getDescription()
{
if (postfix.equals("txt"))
return "txt 文本文件(*.txt)";
return "*." + postfix + "文件";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -