Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
JFileChooserでのHTMLファイルフィルター
class HtmlFilter extends FileFilter{
public boolean accept(File f){
if (f.isDirectory()){
return true;
}
String ext = getExtension(f);
if (ext != null){
if (ext.equals("html") || ext.equals("htm")){
return true;
}else{
return false;
}
}
return false;
}
@Override
public String getDescription() {
return "HTMLファイル";
}
private String getExtension(File f){
String ext = null;
String filename = f.getName();
int dotIndex = filename.lastIndexOf('.');
if ((dotIndex > 0) && (dotIndex < filename.length() - 1)){
ext = filename.substring(dotIndex + 1).toLowerCase();
}
return ext;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment