File Dialogs in Clojure

(See my full list of Clojure Swing examples and tutorials at Clojure Swing Interop)

When dealing with files, its very handy to use file dialogs. Here’s a quick example of using a JFileChooser  to select a file to slurp  and print.

Note the use of  (into-array [“txt”]) as an argument to the FileNameExtensionFilter constructor. This is because the file extensions are provided as a String...  meaning a java.lang.String  array.

Also note, the .showOpenDialog  call uses nil  instead of a JFrame . We do that because we don’t have a JFrame  showing that we want to associate the file dialog with.


Leave a Reply

Your email address will not be published. Required fields are marked *