Skip to content

Instantly share code, notes, and snippets.

@ochilab
Created January 20, 2017 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ochilab/de9f064c8dcb6a1733fd4d8da54d212e to your computer and use it in GitHub Desktop.
Save ochilab/de9f064c8dcb6a1733fd4d8da54d212e to your computer and use it in GitHub Desktop.
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