how to have multiple extensions in one filter java

www.lau‮irutt‬.com
how to have multiple extensions in one filter java

To specify multiple extensions in a filter in Java, you can use the FileNameExtensionFilter class from the javax.swing.filechooser package, which is a FileFilter implementation that filters files based on their file name extensions.

Here's an example of how you can create a FileNameExtensionFilter with multiple extensions:

import javax.swing.filechooser.FileNameExtensionFilter;

// ...

String[] extensions = {"txt", "pdf", "doc"};
FileNameExtensionFilter filter = new FileNameExtensionFilter("Text files", extensions);

In this example, the extensions array is a string array containing the file name extensions to be accepted by the filter. The FileNameExtensionFilter constructor takes a description of the filter and the accepted extensions as arguments.

You can use the filter object to filter files in a JFileChooser or any other component that uses a FileFilter.

Created Time:2017-11-01 20:42:55  Author:lautturi